OrderController.php 103 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\shop\classes\ShopExtClass;
  4. use bizGhs\express\services\DadaExpressServices;
  5. use bizGhs\ghs\classes\GhsClass;
  6. use bizHd\purchase\classes\PurchaseClass;
  7. use bizHd\purchase\services\PurchaseService;
  8. use bizHd\wx\classes\WxOpenClass;
  9. use bizGhs\custom\classes\CustomClass;
  10. use bizGhs\order\classes\OrderClass;
  11. use bizGhs\order\services\OrderService;
  12. use bizHd\saas\services\RegionService;
  13. use bizGhs\product\classes\ProductClass;
  14. use common\components\baiduAip;
  15. use common\components\dict;
  16. use common\components\dateUtil;
  17. use common\components\freight;
  18. use common\components\httpUtil;
  19. use common\components\noticeUtil;
  20. use common\components\oss;
  21. use common\components\payUtil;
  22. use common\components\qrCodeUtil;
  23. use Yii;
  24. use common\components\util;
  25. use biz\shop\classes\ShopAdminClass;
  26. use biz\notice\classes\NoticeClass;
  27. use biz\wx\classes\WxMessageClass;
  28. use biz\shop\classes\ShopClass;
  29. use common\components\lakala\Lakala;
  30. class OrderController extends BaseController
  31. {
  32. public $guestAccess = ['create-order', 'order-relate', 'fast-pay', 'info'];
  33. //修改平账标识状态 ssh 20240405
  34. public function actionModifyClearSign()
  35. {
  36. $get = Yii::$app->request->get();
  37. $id = $get['id'] ?? '';
  38. $order = OrderClass::getById($id, true);
  39. if (empty($order)) {
  40. util::fail('没有找到订单');
  41. }
  42. if ($order->mainId != $this->mainId) {
  43. util::fail('不是你的订单');
  44. }
  45. if (!in_array($order->status, [3, 4])) {
  46. util::fail('订单没有发货');
  47. }
  48. if ($order->clearSign == 1) {
  49. util::fail('不需要重复操作');
  50. }
  51. $connection = Yii::$app->db;
  52. $transaction = $connection->beginTransaction();
  53. try {
  54. $order->clearSign = 1;
  55. $order->save();
  56. $cgId = $order->purchaseId;
  57. $cg = PurchaseClass::getById($cgId, true);
  58. if (empty($cg)) {
  59. util::fail('没有找到采购信息');
  60. }
  61. $cg->clearSign = 1;
  62. $cg->save();
  63. $transaction->commit();
  64. util::complete();
  65. } catch (\Exception $e) {
  66. $transaction->rollBack();
  67. Yii::error("操作失败原因:" . $e->getMessage());
  68. util::fail('操作失败');
  69. }
  70. }
  71. //下载图片版订单 ssh 20240321
  72. public function actionDown()
  73. {
  74. $get = Yii::$app->request->get();
  75. $id = $get['id'] ?? '';
  76. $all = $get['all'] ?? 0;
  77. $order = OrderClass::getById($id, true);
  78. if (empty($order)) {
  79. util::fail('没有找到订单');
  80. }
  81. if ($order->mainId != $this->mainId) {
  82. util::fail('不是你的订单');
  83. }
  84. $customName = $order->customName ?? '';
  85. $date = date("Ymd", strtotime($order->addTime));
  86. $orderSn = $order->orderSn ?? '';
  87. $name = $customName . '_' . $date . '_' . $orderSn;
  88. $shop = $this->shop;
  89. $staff = $this->shopAdmin;
  90. $respond = OrderClass::createImgOrder($order, $shop, $staff, $all);
  91. $imgUrl = $respond['imgFile'] ?? '';
  92. $file = fopen($imgUrl, "rb");
  93. Header("Content-type: application/octet-stream ");
  94. Header("Accept-Ranges: bytes ");
  95. Header("Content-Disposition: attachment;filename={$name}.png");
  96. $contents = "";
  97. while (!feof($file)) {
  98. $contents .= fread($file, 8192);
  99. }
  100. echo $contents;
  101. fclose($file);
  102. }
  103. //确认送达
  104. public function actionConfirmReach()
  105. {
  106. $get = Yii::$app->request->get();
  107. $id = $get['id'] ?? '';
  108. $order = OrderClass::getById($id, true);
  109. if (empty($order)) {
  110. util::fail('没有找到订单');
  111. }
  112. if ($order->mainId != $this->mainId) {
  113. util::fail('不是你的订单');
  114. }
  115. if ($order->status == 1) {
  116. util::fail('订单待付款');
  117. }
  118. if ($order->status == 4) {
  119. util::fail('订单已完成');
  120. }
  121. if ($order->status == 5) {
  122. util::fail('订单已取消');
  123. }
  124. $connection = Yii::$app->db;
  125. $transaction = $connection->beginTransaction();
  126. try {
  127. OrderClass::confirmReach($order);
  128. $transaction->commit();
  129. util::complete('操作成功');
  130. } catch (\Exception $e) {
  131. $transaction->rollBack();
  132. Yii::error("操作失败原因:" . $e->getMessage());
  133. util::fail('确认失败');
  134. }
  135. }
  136. public function actionAllFh()
  137. {
  138. $post = Yii::$app->request->post();
  139. $ids = $post['ids'] ?? '';
  140. if (empty($ids)) {
  141. util::fail('请选择要合并发货的订单');
  142. }
  143. $arr = explode(',', $ids);
  144. if (empty($arr)) {
  145. util::fail('请选择要合并发货的订单哦');
  146. }
  147. $fhWl = $post['fhWl'] ?? '';
  148. $fhWlNo = $post['fhWlNo'] ?? '';
  149. $fhType = 0;
  150. $params = [
  151. 'fhType' => $fhType,
  152. 'fhWl' => $fhWl,
  153. 'fhWlNo' => $fhWlNo,
  154. ];
  155. $connection = Yii::$app->db;
  156. $transaction = $connection->beginTransaction();
  157. try {
  158. $all = OrderClass::getAllByCondition(['id' => ['in', $arr]], null, '*', null, true);
  159. foreach ($all as $order) {
  160. if ($order->book == 1) {
  161. util::fail('有预订单,不能一起发货');
  162. }
  163. if ($order->mainId != $this->mainId) {
  164. util::fail('不是你的订单哦');
  165. }
  166. OrderClass::orderSend($order, $params, true);
  167. }
  168. $transaction->commit();
  169. util::complete();
  170. } catch (\Exception $e) {
  171. $transaction->rollBack();
  172. Yii::error("操作失败原因:" . $e->getMessage());
  173. util::fail('操作失败');
  174. }
  175. }
  176. //发货 ssh 20230613
  177. public function actionFh()
  178. {
  179. $post = Yii::$app->request->post();
  180. $id = $post['id'] ?? '';
  181. $order = OrderClass::getById($id, true);
  182. OrderClass::valid($order, $this->shopId);
  183. $fhWl = $post['fhWl'] ?? '';
  184. $fhWlNo = $post['fhWlNo'] ?? '';
  185. $fhType = $post['fhType'] ?? '';
  186. $params = [
  187. 'fhType' => $fhType,
  188. 'fhWl' => $fhWl,
  189. 'fhWlNo' => $fhWlNo,
  190. ];
  191. if ($order->book == 1) {
  192. util::fail('预订单不支持这个发货方式');
  193. }
  194. $connection = Yii::$app->db;
  195. $transaction = $connection->beginTransaction();
  196. try {
  197. OrderClass::orderSend($order, $params);
  198. $transaction->commit();
  199. util::complete();
  200. } catch (\Exception $e) {
  201. $transaction->rollBack();
  202. Yii::error("操作失败原因:" . $e->getMessage());
  203. util::fail('操作失败');
  204. }
  205. }
  206. //合并打印 ssh 20230929
  207. public function actionMergePrint()
  208. {
  209. $post = Yii::$app->request->post();
  210. $ids = $post['ids'] ?? '';
  211. if (empty($ids)) {
  212. util::fail('请选择要合并打印的订单');
  213. }
  214. $arr = explode(',', $ids);
  215. if (empty($arr)) {
  216. util::fail('请选择要合并打印的订单哦');
  217. }
  218. if (getenv('YII_ENV') == 'production') {
  219. if ($this->mainId != 10536 && $this->mainId != 50) {
  220. //util::fail('功能开发中');
  221. }
  222. } else {
  223. if ($this->mainId != 11) {
  224. //util::fail('功能开发中');
  225. }
  226. }
  227. OrderClass::mergePrintOrder($arr, $this->mainId);
  228. util::complete('打印成功');
  229. }
  230. //修改分工 ssh 20221129
  231. public function actionChangeWorker()
  232. {
  233. $post = Yii::$app->request->post();
  234. $id = $post['id'] ?? 0;
  235. $shopAdminId = $post['shopAdminId'] ?? 0;
  236. $shopAdminName = $post['shopAdminName'] ?? '';
  237. $order = OrderClass::getById($id, true);
  238. OrderClass::valid($order, $this->shopId);
  239. $preShopAdminId = $order->shopAdminId ?? 0;
  240. if (!empty($preShopAdminId)) {
  241. $shopAdmin = $this->shopAdmin;
  242. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  243. util::fail('管理员才能操作');
  244. }
  245. }
  246. $order->shopAdminId = $shopAdminId;
  247. $order->shopAdminName = $shopAdminName;
  248. $order->save();
  249. util::complete();
  250. }
  251. //预订单到货 ssh 20220321
  252. public function actionArrival()
  253. {
  254. $post = Yii::$app->request->post();
  255. $id = $post['id'] ?? 0;
  256. $connection = Yii::$app->db;
  257. $transaction = $connection->beginTransaction();
  258. try {
  259. $order = OrderClass::getById($id, true);
  260. OrderClass::valid($order, $this->shopId);
  261. $post['shopAdminId'] = $this->shopAdminId;
  262. $post['shopAdminName'] = $this->shopAdmin ? $this->shopAdmin->name : '';
  263. OrderService::arrival($order, $post);
  264. $transaction->commit();
  265. util::success($order);
  266. } catch (\Exception $e) {
  267. $transaction->rollBack();
  268. Yii::error("操作失败原因:" . $e->getMessage());
  269. util::fail('操作失败');
  270. }
  271. }
  272. //到货获取订单详情 ssh 20220323
  273. public function actionArrivalDetail()
  274. {
  275. $get = Yii::$app->request->get();
  276. $id = $get['id'] ?? 0;
  277. $info = OrderClass::getById($id);
  278. OrderClass::valid($info, $this->shopId);
  279. $showItemData = OrderClass::getOriginalShowItem(true, $info);
  280. $itemList = $showItemData['list'] ?? [];
  281. $info['product'] = $itemList;
  282. $kiloFee = $this->shop->kiloFee ?? 0;
  283. $miniKilo = $this->shop->miniKilo ?? 0;
  284. $info['kiloFee'] = $kiloFee;
  285. $info['miniKilo'] = $miniKilo;
  286. util::success($info);
  287. }
  288. //支付宝扫码支付 ssh 20210103
  289. public function actionScanPayCheck()
  290. {
  291. $get = Yii::$app->request->get();
  292. $id = isset($get['id']) ? $get['id'] : 0;
  293. $order = OrderClass::getById($id, true);
  294. if ($order->status != OrderClass::ORDER_STATUS_UN_PAY && $order->status != OrderClass::ORDER_STATUS_CANCEL) {
  295. util::success(['returnStatus' => 'SUCCESS']);
  296. }
  297. $deadline = $order->deadline ?? '';
  298. $deadTime = strtotime($deadline);
  299. $current = time();
  300. $diff = bcsub($deadTime, $current);
  301. if ($diff <= 60) {
  302. util::success(['returnStatus' => 'EXPIRE']);
  303. }
  304. util::success(['returnStatus' => 'FAILURE']);
  305. }
  306. //微信和支付宝扫码支付 ssh 20210103
  307. public function actionScanPay()
  308. {
  309. ini_set('date.timezone', 'Asia/Shanghai');
  310. header("Content-type: text/html; charset=utf-8");
  311. $get = Yii::$app->request->get();
  312. $id = isset($get['id']) ? $get['id'] : 0;
  313. $order = OrderClass::getById($id, true);
  314. if (isset($order->status) == false || $order->status != 1) {
  315. util::success(['returnStatus' => 'FAILURE'], '不是待付款订单');
  316. }
  317. OrderClass::valid($order, $this->shopId);
  318. $cgId = $order->purchaseId ?? 0;
  319. $cg = PurchaseClass::getById($cgId, true);
  320. $orderSn = $cg->orderSn ?? '';
  321. if (empty($orderSn)) {
  322. util::success(['returnStatus' => 'FAILURE'], '没有找到采购单');
  323. }
  324. $deadline = $cg->deadline;
  325. $current = date("Y-m-d H:i:s");
  326. if ((strtotime($deadline) + 20) < strtotime($current)) {
  327. util::success(['returnStatus' => 'FAILURE'], '订单已经失效');
  328. }
  329. $totalFee = $cg->actPrice ?? 0;
  330. $subject = '购买鲜花';
  331. $totalAmount = $totalFee;
  332. $body = "到店订单";
  333. //标记为扫码支付 和 自取订单
  334. $order->codePay = 2;
  335. $order->sendType = OrderClass::SEND_TYPE_NO;
  336. $order->save();
  337. $cg->getType = PurchaseClass::GET_TYPE_SELF_GET;
  338. $cg->codePay = 2;
  339. $cg->save();
  340. $shop = $this->shop;
  341. $currentCapitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  342. $wxPayWay = dict::getDict('payWay', 'wxPay');
  343. $aliPayWay = dict::getDict('payWay', 'alipay');
  344. $payWay = Yii::$app->request->get('payWay', $wxPayWay);
  345. if ($payWay == $wxPayWay) {
  346. if (isset($order->wxPayUrl) && !empty($order->wxPayUrl)) {
  347. $url = $order->wxPayUrl;
  348. } else {
  349. util::fail('暂不支持');
  350. $merchantExtend = WxOpenClass::getWxInfo();
  351. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  352. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  353. $params = [
  354. 'appid' => 'OP00002119',
  355. 'serial_no' => '018b08cfddbd',
  356. 'merchant_no' => $shop->lklSjNo,
  357. 'term_no' => $shop->lklScanTermNo,
  358. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  359. 'lklCertificatePath' => $lklCertificatePath,
  360. ];
  361. $laResource = new Lakala($params);
  362. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
  363. $wxParams = [
  364. 'orderSn' => $orderSn,
  365. 'amount' => $totalFee,
  366. 'capitalType' => $currentCapitalType,
  367. 'notifyUrl' => $notifyUrl,
  368. 'subject' => $subject,
  369. 'couponId' => 0,
  370. 'wxAppId' => $merchantExtend['miniAppId'],
  371. ];
  372. $response = $laResource->driveNativeWxPay($wxParams);
  373. if (isset($response['code']) == false || $response['code'] != 'BBS00000') {
  374. $msg = $response['msg'] ?? '';
  375. noticeUtil::push($msg, '15280215347');
  376. util::fail('二维码生成失败');
  377. }
  378. $url = isset($response['resp_data']['acc_resp_fields']['code']) ? $response['resp_data']['acc_resp_fields']['code'] : '';
  379. if (empty($url)) {
  380. util::fail('二维码生成失败..');
  381. }
  382. $order->wxPayUrl = $url;
  383. $order->save();
  384. }
  385. $suffixUrl = qrCodeUtil::generateShortTimeGatheringQrCode($url, $this->sjId, $this->shopId, $payWay);
  386. $payUrl = Yii::$app->params['ghsImgHost'] . $suffixUrl;
  387. util::success(['url' => $payUrl, 'returnStatus' => 'SUCCESS']);
  388. }
  389. if ($payWay == $aliPayWay) {
  390. if (isset($order->aliPayUrl) && !empty($order->aliPayUrl)) {
  391. $url = $order->aliPayUrl;
  392. } else {
  393. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  394. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  395. $params = [
  396. 'appid' => 'OP00002119',
  397. 'serial_no' => '018b08cfddbd',
  398. 'merchant_no' => $shop->lklSjNo,
  399. 'term_no' => $shop->lklScanTermNo,
  400. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  401. 'lklCertificatePath' => $lklCertificatePath,
  402. ];
  403. $laResource = new Lakala($params);
  404. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
  405. $aliParams = [
  406. 'orderSn' => $orderSn,
  407. 'amount' => $totalFee,
  408. 'capitalType' => $currentCapitalType,
  409. 'notifyUrl' => $notifyUrl,
  410. 'subject' => $subject,
  411. ];
  412. $response = $laResource->driveAliPay($aliParams);
  413. if (isset($response['code']) == false || $response['code'] != 'BBS00000') {
  414. util::fail('二维码生成失败');
  415. }
  416. $url = isset($response['resp_data']['acc_resp_fields']['code']) ? $response['resp_data']['acc_resp_fields']['code'] : '';
  417. if (empty($url)) {
  418. util::fail('二维码生成失败..');
  419. }
  420. $order->aliPayUrl = $url;
  421. $order->save();
  422. }
  423. $suffixUrl = qrCodeUtil::generateShortTimeGatheringQrCode($url, $this->sjId, $this->shopId, $payWay);
  424. $payUrl = Yii::$app->params['ghsImgHost'] . $suffixUrl;
  425. util::success(['url' => $payUrl, 'returnStatus' => 'SUCCESS']);
  426. }
  427. util::success(['returnStatus' => 'FAILURE'], '不支持的收款方式');
  428. }
  429. //微信和支付宝付款码支付复查 ssh 20211231
  430. public function actionCodePayCheck()
  431. {
  432. ini_set('date.timezone', 'Asia/Shanghai');
  433. header("Content-type: text/html; charset=utf-8");
  434. $get = Yii::$app->request->get();
  435. $id = isset($get['id']) ? $get['id'] : 0;
  436. $order = OrderClass::getById($id, true);
  437. if (empty($order)) {
  438. util::success(['returnStatus' => 'SUCCESS']);
  439. }
  440. if ($order->status == OrderClass::ORDER_STATUS_COMPLETE) {
  441. util::complete('订单已付款');
  442. }
  443. if ($order->status != OrderClass::ORDER_STATUS_UN_PAY) {
  444. util::complete('订单不是待付款状态');
  445. }
  446. OrderClass::valid($order, $this->shopId);
  447. $cgId = $order->purchaseId ?? 0;
  448. $cg = PurchaseClass::getById($cgId, true);
  449. $orderSn = $cg->orderSn ?? '';
  450. $totalFee = $cg->actPrice ?? 0;
  451. if (empty($orderSn)) {
  452. util::complete('没有找到采购单');
  453. }
  454. $connection = Yii::$app->db;
  455. $transaction = $connection->beginTransaction();
  456. try {
  457. $capitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  458. $shop = $this->shop;
  459. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  460. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  461. $params = [
  462. 'appid' => 'OP00002119',
  463. 'serial_no' => '018b08cfddbd',
  464. 'merchant_no' => $shop->lklSjNo,
  465. 'term_no' => $shop->lklScanTermNo,
  466. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  467. 'lklCertificatePath' => $lklCertificatePath,
  468. ];
  469. $laResource = new Lakala($params);
  470. $scanParams = ['orderSn' => $orderSn,];
  471. $response = $laResource->query($scanParams);
  472. if (isset($response['code']) && $response['code'] == 'BBS00000') {
  473. if (isset($response['resp_data']['trade_state']) && $response['resp_data']['trade_state'] == 'SUCCESS') {
  474. //支付成功
  475. $transactionId = $response['resp_data']['trade_no'] ?? '';
  476. $openId = '';
  477. $aliUserId = '';
  478. $cg->onlinePay = dict::getDict('onlinePay', 'yes');
  479. $cg->codePay = 1;
  480. $cg->payOpenId = $openId;
  481. $cg->aliUserId = $aliUserId;
  482. //自取订单
  483. $cg->getType = PurchaseClass::GET_TYPE_SELF_GET;
  484. $cg->save();
  485. $order->onlinePay = dict::getDict('onlinePay', 'yes');
  486. $order->codePay = 1;
  487. //自取订单
  488. $order->sendType = OrderClass::SEND_TYPE_NO;
  489. $order->save();
  490. $payWayType = dict::getDict('payWay', 'wxPay');
  491. $account_type = $response['resp_data']['account_type'] ?? '';
  492. if ($account_type == 'WECHAT') {
  493. $payWayType = dict::getDict('payWay', 'wxPay');
  494. }
  495. if ($account_type == 'ALIPAY') {
  496. $payWayType = dict::getDict('payWay', 'alipay');
  497. }
  498. $order->payWay = $payWayType;
  499. $order->save();
  500. $cg->payWay = $payWayType;
  501. $cg->save();
  502. $attach = '';
  503. payUtil::thirdPay($payWayType, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  504. $transaction->commit();
  505. $saleId = $order->id ?? 0;
  506. $order = OrderClass::getById($saleId, true);
  507. if (!empty($order)) {
  508. //解决扫码付重复打印问题
  509. $cacheKey = 'scan_pay_print_order_' . $orderSn;
  510. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  511. if (!empty($has)) {
  512. return false;
  513. }
  514. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 1, 'has']);
  515. //订单生成时唤起在线打印
  516. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  517. if ($order->status != 1 && $order->status != 5) {
  518. OrderClass::onlinePrint($order);
  519. $ext = $this->shopExt;
  520. if (isset($ext->printSn) && !empty($ext->printSn)) {
  521. $order->printNum += 1;
  522. $order->save();
  523. }
  524. }
  525. }
  526. ShopExtClass::ghsGatheringReport($order);
  527. }
  528. util::success(['returnStatus' => 'SUCCESS']);
  529. } else {
  530. util::complete('未知状态..');
  531. }
  532. } else {
  533. util::complete('未知状态....');
  534. }
  535. } catch (\Exception $e) {
  536. $transaction->rollBack();
  537. noticeUtil::push('查询订单状态失败:' . $e->getMessage(), '15280215347');
  538. util::fail('支付失败');
  539. }
  540. }
  541. //微信和支付宝付款码支付 ssh 2021.4.11
  542. public function actionCodePay()
  543. {
  544. ini_set('date.timezone', 'Asia/Shanghai');
  545. header("Content-type: text/html; charset=utf-8");
  546. $get = Yii::$app->request->get();
  547. $id = isset($get['id']) ? $get['id'] : 0;
  548. $order = OrderClass::getById($id, true);
  549. if (isset($order->status) == false || $order->status != 1) {
  550. util::fail('不是待付款订单');
  551. }
  552. OrderClass::valid($order, $this->shopId);
  553. $cgId = $order->purchaseId ?? 0;
  554. $cg = PurchaseClass::getById($cgId, true);
  555. $orderSn = $cg->orderSn ?? '';
  556. if (empty($orderSn)) {
  557. util::fail('没有找到采购单');
  558. }
  559. //付款码
  560. $authCode = (string)$get['authCode'] ?? '';
  561. if (empty($authCode)) {
  562. util::fail('支付失败');
  563. }
  564. $deadline = $cg->deadline;
  565. $current = date("Y-m-d H:i:s");
  566. if ((strtotime($deadline) + 20) < strtotime($current)) {
  567. util::fail('订单已经失效');
  568. }
  569. $totalFee = $cg->actPrice ?? 0;
  570. $connection = Yii::$app->db;
  571. $transaction = $connection->beginTransaction();
  572. try {
  573. $subject = '购买花材';
  574. $capitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
  575. $shop = $this->shop;
  576. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  577. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  578. $params = [
  579. 'appid' => 'OP00002119',
  580. 'serial_no' => '018b08cfddbd',
  581. 'merchant_no' => $shop->lklSjNo,
  582. 'term_no' => $shop->lklScanTermNo,
  583. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  584. 'lklCertificatePath' => $lklCertificatePath,
  585. ];
  586. $laResource = new Lakala($params);
  587. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
  588. $scanParams = [
  589. 'orderSn' => $orderSn,
  590. 'amount' => $totalFee,
  591. 'capitalType' => $capitalType,
  592. 'notifyUrl' => $notifyUrl,
  593. 'subject' => $subject,
  594. 'authCode' => $authCode,
  595. ];
  596. $response = $laResource->scanPay($scanParams);
  597. if (isset($response['code']) && $response['code'] == 'BBS00000') {
  598. $account_type = $response['resp_data']['account_type'] ?? '';
  599. $payWayType = dict::getDict('payWay', 'wxPay');
  600. if ($account_type == 'WECHAT') {
  601. $payWayType = dict::getDict('payWay', 'wxPay');
  602. }
  603. if ($account_type == 'ALIPAY') {
  604. $payWayType = dict::getDict('payWay', 'alipay');
  605. }
  606. $order->payWay = $payWayType;
  607. $order->save();
  608. $cg->payWay = $payWayType;
  609. $cg->save();
  610. $transactionId = $response['resp_data']['trade_no'] ?? '';
  611. $openId = '';
  612. $aliUserId = '';
  613. $cg->onlinePay = dict::getDict('onlinePay', 'yes');
  614. $cg->codePay = 1;
  615. $cg->payOpenId = $openId;
  616. $cg->aliUserId = $aliUserId;
  617. //自取订单
  618. $cg->getType = PurchaseClass::GET_TYPE_SELF_GET;
  619. $cg->save();
  620. $order->onlinePay = dict::getDict('onlinePay', 'yes');
  621. $order->codePay = 1;
  622. //自取订单
  623. $order->sendType = OrderClass::SEND_TYPE_NO;
  624. $order->save();
  625. $attach = '';
  626. payUtil::thirdPay($payWayType, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  627. $transaction->commit();
  628. $saleId = $order->id ?? 0;
  629. $order = OrderClass::getById($saleId, true);
  630. if (!empty($order)) {
  631. //解决扫码付重复打印问题
  632. $cacheKey = 'scan_pay_print_order_' . $orderSn;
  633. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  634. if (!empty($has)) {
  635. return false;
  636. }
  637. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 1, 'has']);
  638. //订单生成时唤起在线打印
  639. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  640. if ($order->status != 1 && $order->status != 5) {
  641. OrderClass::onlinePrint($order);
  642. $ext = $this->shopExt;
  643. if (isset($ext->printSn) && !empty($ext->printSn)) {
  644. $order->printNum += 1;
  645. $order->save();
  646. }
  647. }
  648. }
  649. ShopExtClass::ghsGatheringReport($order);
  650. }
  651. util::success(['returnStatus' => 'SUCCESS']);
  652. } else {
  653. $msg = $response['msg'] ?? '';
  654. util::success(['returnStatus' => 'FAILURE'], $msg);
  655. }
  656. } catch (\Exception $e) {
  657. $transaction->rollBack();
  658. Yii::error("支付失败原因:" . $e->getMessage());
  659. util::fail('支付失败');
  660. }
  661. }
  662. //订单列表 ssh 2021.1.20
  663. public function actionList()
  664. {
  665. $get = Yii::$app->request->get();
  666. $where['mainId'] = $this->mainId;
  667. $status = $get['status'] ?? 0;
  668. if (!empty($status)) {
  669. $where['status'] = $status;
  670. }
  671. $clearSign = $get['clearSign'] ?? -1;
  672. if ($clearSign > -1) {
  673. $where['clearSign'] = $clearSign;
  674. }
  675. $book = $get['book'] ?? -1;
  676. if ($book > -1) {
  677. $where['book'] = $book;
  678. }
  679. $searchTime = $get['searchTime'] ?? '';
  680. if (!empty($searchTime)) {
  681. $startTime = $get['startTime'] ?? '';
  682. $endTime = $get['endTime'] ?? '';
  683. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  684. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  685. }
  686. $name = $get['name'] ?? '';
  687. if (!empty($name)) {
  688. $searchType = $get['searchType'] ?? 0;
  689. if (empty($searchType)) {
  690. //订单编号
  691. if (strpos($name, 'XSD') === 0) {
  692. $where['orderSn'] = $name;
  693. } elseif (preg_match("/^[a-zA-Z\s]+$/", $name)) {
  694. $where['customNamePy'] = ['like', $name];
  695. } else {
  696. $where['customName'] = ['like', $name];
  697. }
  698. } elseif ($searchType == 1) {
  699. $where['sendNum'] = $name;
  700. } else {
  701. }
  702. }
  703. if (isset($get['customId']) && !empty($get['customId'])) {
  704. $where['customId'] = $get['customId'];
  705. }
  706. if (isset($get['ids']) && !empty($get['ids'])) {
  707. $stringIds = $get['ids'];
  708. $newIds = explode(',', $stringIds);
  709. $where['id'] = ['in', $newIds];
  710. }
  711. $respond = OrderClass::getOrderList($where);
  712. $respond['shop'] = $this->shop;
  713. $respond['shopExt'] = $this->shopExt;
  714. util::success($respond);
  715. }
  716. // 新订单列表详情 -- 可能与 actionList 很相似,但为不影响 actionList,重新创建个方法 shizhongqi 2022.06.23
  717. public function actionNewOrderList()
  718. {
  719. $get = Yii::$app->request->get();
  720. $where['shopId'] = $this->shopId;
  721. /*$status = $get['status'] ?? 0;
  722. if (!empty($status)) {
  723. $where['status'] = $status;
  724. }*/
  725. // 按类别生成查询条件:1.今日实收 2.今日欠款 3.总欠款(所有历史欠款)
  726. if (isset($get['type'])) {
  727. $type = $get['type'];
  728. if ($type == 1) { // 今日实收
  729. $get['searchTime'] = 'today';
  730. $where['debt'] = 0;
  731. $where['debtPrice'] = '0.00';
  732. $where['status'] = ['in', [OrderClass::ORDER_STATUS_UN_SEND, OrderClass::ORDER_STATUS_SENDING, OrderClass::ORDER_STATUS_COMPLETE]];
  733. } elseif ($type == 2) { // 今日欠款
  734. $get['searchTime'] = 'today';
  735. $where['debt'] = 1;
  736. } elseif ($type == 3) { // 总欠款
  737. $where['debt'] = 1;
  738. } else {
  739. util::fail('查询的订单类别不存在');
  740. }
  741. }
  742. $searchTime = $get['searchTime'] ?? '';
  743. if (!empty($searchTime)) {
  744. $startTime = '';
  745. $endTime = '';
  746. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  747. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  748. }
  749. $name = $get['name'] ?? '';
  750. if (!empty($name)) {
  751. $searchType = $get['searchType'] ?? 0;
  752. if (empty($searchType)) {
  753. //订单编号
  754. if (strpos($name, 'XSD') === 0) {
  755. $where['orderSn'] = $name;
  756. } elseif (preg_match("/^[a-zA-Z\s]+$/", $name)) {
  757. $where['customNamePy'] = ['like', $name];
  758. } else {
  759. $where['customName'] = ['like', $name];
  760. }
  761. } elseif ($searchType == 1) {
  762. $where['sendNum'] = $name;
  763. } else {
  764. util::fail('搜索的订单类别不存在');
  765. }
  766. }
  767. $respond = OrderClass::getOrderList($where);
  768. $respond['shop'] = $this->shop;
  769. $respond['shopExt'] = $this->shopExt;
  770. $respond['type'] = $type; //把查询类别返回
  771. util::success($respond);
  772. }
  773. //商城下单操作 ssh 2021.1.14
  774. public function actionCreateOrder()
  775. {
  776. $post = Yii::$app->request->post();
  777. $shopId = $this->shopId;
  778. $customId = $post['customId'] ?? 0;
  779. $post['customId'] = $customId;
  780. //开单必须选客户
  781. if (empty($customId)) {
  782. util::fail('请选择客户');
  783. }
  784. $custom = CustomClass::getCustom($customId);
  785. if (empty($custom)) {
  786. util::fail('请选客户哦');
  787. }
  788. $shopAdmin = $this->shopAdmin;
  789. $shopAdminId = $this->shopAdminId;
  790. $shopAdminName = $shopAdmin->name ?? '';
  791. //n秒内不允许重复提交,有多个地方要同步修改,关键词ghs_custom_create_order_redis
  792. $createOrderCacheKey = 'ghs_custom_create_order_' . $customId . '_' . $shopAdminId;
  793. $has = Yii::$app->redis->executeCommand('GET', [$createOrderCacheKey]);
  794. if (!empty($has)) {
  795. util::fail('已提交过,5秒后再试');
  796. }
  797. Yii::$app->redis->executeCommand('SETEX', [$createOrderCacheKey, 5, 'has']);
  798. CustomClass::valid($custom, $this->shopId);
  799. if (isset($custom['mainId']) && !empty($custom['mainId']) && $custom['mainId'] == $custom['ownMainId']) {
  800. util::fail('不能给自己开单');
  801. }
  802. $post['ghsId'] = $custom['ghsId'] ?? 0;
  803. $post['customMobile'] = $custom['mobile'] ?? '';
  804. $customName = $custom['name'] ?? '';
  805. $post['customName'] = $customName;
  806. $post['customNamePy'] = $custom['py'] ?? '';
  807. $post['customAvatar'] = $custom['shortSmallAvatar'] ?? '';
  808. $post['province'] = $custom['province'] ?? '';
  809. $post['city'] = $custom['city'] ?? '';
  810. $post['dist'] = $custom['dist'] ?? '';
  811. $post['address'] = $custom['address'] ?? '';
  812. $post['floor'] = $custom['floor'] ?? '';
  813. $post['fullAddress'] = $custom['fullAddress'] ?? '';
  814. $post['showAddress'] = $custom['showAddress'] ?? '';
  815. $post['long'] = $custom['long'] ?? '';
  816. $post['lat'] = $custom['lat'] ?? '';
  817. if (isset($post['getStaffId']) == true && !empty($post['getStaffId'])) {
  818. $getStaffName = $post['getStaffName'] ?? '';
  819. $shopAdminId = $post['getStaffId'];
  820. $shopAdminName = $getStaffName;
  821. } else {
  822. if (getenv('YII_ENV') == 'production') {
  823. //鹏诚需要选择开单人
  824. if (in_array($this->mainId, [19606])) {
  825. util::fail('请选择开单人');
  826. }
  827. } else {
  828. if (in_array($this->mainId, [])) {
  829. util::fail('请选择开单人');
  830. }
  831. }
  832. }
  833. if (getenv('YII_ENV') == 'production') {
  834. //小向花卉开单售后控制
  835. if ($this->mainId == 23390) {
  836. if (!in_array($this->adminId, [24043, 24585, 24586, 24654, 24115, 23960])) {
  837. util::fail('你不能开单哦');
  838. }
  839. }
  840. } else {
  841. if ($this->mainId == 644) {
  842. // if (!in_array($this->adminId, [919])) {
  843. // util::fail('你不能开单哈');
  844. // }
  845. }
  846. }
  847. //开单人和收款人必定是同个人
  848. $post['shopAdminId'] = $shopAdminId;
  849. $post['shopAdminName'] = $shopAdminName;
  850. $post['getStaffId'] = $shopAdminId;
  851. $post['getStaffName'] = $shopAdminName;
  852. $post['sjId'] = $this->sjId;
  853. $post['shopId'] = $shopId;
  854. $post['mainId'] = $this->mainId;
  855. $post['fromType'] = 1;
  856. $post['expressId'] = $post['expressId'] ?? 0;
  857. $book = $post['book'] ?? 0;
  858. $post['book'] = $book;
  859. $sendType = $post['sendType'] ?? 0;
  860. $transType = $post['transType'] ?? 0;
  861. $shop = $this->shop;
  862. if (isset($shop->pfLevel) && $shop->pfLevel == 1) {
  863. //昆明发往全国
  864. $sendCost = isset($post['sendCost']) && $post['sendCost'] > 0 ? $post['sendCost'] : 0;
  865. $post['sendCost'] = $sendCost;
  866. $packCost = isset($post['packCost']) && $post['packCost'] > 0 ? $post['packCost'] : 0;
  867. $post['packCost'] = $packCost;
  868. $post['transType'] = $transType;
  869. $post['localOrder'] = 1;
  870. } else {
  871. //同步配送
  872. $sendCost = isset($post['sendCost']) && $post['sendCost'] > 0 ? $post['sendCost'] : 0;
  873. if ($sendType != dict::getDict('sendType', 'thirdSend') && $sendCost > 0) {
  874. util::fail('填了运费,请选择代叫跑腿');
  875. }
  876. $post['sendCost'] = $sendCost;
  877. $post['packCost'] = isset($post['packCost']) && $post['packCost'] > 0 ? $post['packCost'] : 0;
  878. }
  879. $hasPay = $post['hasPay'] ?? dict::getDict('hasPay', 'unPay');
  880. $post['debt'] = OrderClass::DEBT_NO;
  881. if ($hasPay == dict::getDict('hasPay', 'debt')) {
  882. $post['debt'] = OrderClass::DEBT_YES;
  883. }
  884. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  885. if ($hasPay == dict::getDict('hasPay', 'payed')) {
  886. //util::fail('没有权限');
  887. }
  888. }
  889. //多颜色数据整理
  890. $colorItem = $post['xj'] ?? [];
  891. $newXj = [];
  892. if (!empty($colorItem)) {
  893. $colorData = json_decode($colorItem, true);
  894. if (!empty($colorData) && is_array($colorData)) {
  895. foreach ($colorData as $colorInfo) {
  896. $ptItemId = $colorInfo['ptItemId'] ?? 0;
  897. $colorList = $colorInfo['list'] ?? [];
  898. if (!empty($colorList)) {
  899. foreach ($colorList as $colorItemKey => $colorItem) {
  900. $newXj[$ptItemId][] = $colorItem;
  901. }
  902. }
  903. }
  904. }
  905. }
  906. $post['xj'] = $newXj;
  907. $productJson = $post['product'] ?? '';
  908. if (empty($productJson)) {
  909. util::fail('请选择花材');
  910. }
  911. $productList = json_decode($productJson, true);
  912. if (empty($productList)) {
  913. util::fail('请选择花材');
  914. }
  915. $dealPrice = $post['dealPrice'] ?? 0;
  916. $ids = array_unique(array_filter(array_column($productList, 'productId')));
  917. $itemInfo = ProductClass::getByIds($ids, null, 'id');
  918. if (empty($itemInfo)) {
  919. util::fail('请选择花材哦');
  920. }
  921. //判断花材有效性
  922. foreach ($itemInfo as $itemData) {
  923. if (isset($itemData['mainId']) == false || $itemData['mainId'] != $this->mainId) {
  924. util::fail('只能选择同一家的商品哈');
  925. }
  926. }
  927. //开单提交订单时,别人修改价格,暂成提交价格不是真实卖价问题解决!!
  928. if ($dealPrice == 0) {
  929. $diff = [];
  930. $priceMap = CustomClass::$levelPriceKeyMap;
  931. $addPriceMap = CustomClass::$levelAddPriceKeyMap;
  932. $level = $custom['level'] ?? 1;
  933. foreach ($productList as $currentKey => $currentProduct) {
  934. $currentPrice = $currentProduct['price'] ?? 0;
  935. $currentId = $currentProduct['productId'] ?? 0;
  936. $systemInfo = $itemInfo[$currentId] ?? [];
  937. $name = $systemInfo['name'] ?? '';
  938. $systemPrice = ProductClass::getFinalPrice($systemInfo, $level, $priceMap, $addPriceMap);
  939. if (floatval($currentPrice) != floatval($systemPrice)) {
  940. $diff[] = [
  941. 'name' => $name,
  942. 'price' => $systemPrice,
  943. 'kdPrice' => $currentPrice,
  944. ];
  945. }
  946. }
  947. if (!empty($diff)) {
  948. //n秒内不允许重复提交,有多个地方要同步修改,关键词ghs_custom_create_order_redis
  949. Yii::$app->redis->executeCommand('DEL', [$createOrderCacheKey]);
  950. util::success(['diff' => $diff, 'respondType' => 'priceError']);
  951. }
  952. }
  953. if ($book == 1) {
  954. $post['hasPay'] = 2;
  955. $post['payWay'] = 0;
  956. }
  957. $historyDate = $post['historyDate'] ?? '';
  958. if (!empty($historyDate)) {
  959. if ($book == 1) {
  960. util::fail('预订单不能选订单日期');
  961. }
  962. if ($hasPay == 0) {
  963. util::fail('扫码付不能选订单日期');
  964. }
  965. if (strtotime($historyDate) > strtotime(date("Y-m-d"))) {
  966. util::fail('订单日期只能选历史时间');
  967. }
  968. }
  969. $connection = Yii::$app->db;//事务处理
  970. $transaction = $connection->beginTransaction();
  971. try {
  972. $post['product'] = $productList;
  973. //商家开单到时间会自动标记为欠款,所以360天内不过期,以保证足够时间标记欠款,具体参数查看dict local_gys_kd_auto_set_debt_time
  974. $time = time();
  975. $hasTime = dict::getDict('order_pay_has_time');
  976. $totalTime = bcadd($time, $hasTime);
  977. $post['deadline'] = date("Y-m-d H:i:s", $totalTime);
  978. $return = OrderService::createFinishOrder($post, $custom, $hasPay);
  979. $transaction->commit();
  980. $saleId = $return->id ?? 0;
  981. $order = OrderClass::getById($saleId, true);
  982. if (!empty($order)) {
  983. $shopId = $order->shopId ?? 0;
  984. $customId = $order->customId ?? 0;
  985. $ghsId = $order->ghsId ?? 0;
  986. $custom = CustomClass::getById($customId, true);
  987. $date = date("Y-m-d H:i:s");
  988. if (!empty($custom)) {
  989. $custom->recentExpend = $date;
  990. $custom->save();
  991. }
  992. $ghs = GhsClass::getById($ghsId, true);
  993. if (!empty($ghs)) {
  994. $ghs->recentExpend = $date;
  995. $ghs->save();
  996. }
  997. $shop = ShopClass::getById($shopId, true);
  998. if (isset($order->payStatus) && $order->payStatus == 1) {
  999. if (!empty($shop)) {
  1000. //通知员工
  1001. $noticeText = json_encode(['orderId' => $saleId]);
  1002. $noticeKey = "hdCgNoticeGhs";
  1003. Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
  1004. //通知花店
  1005. // $noticeText = json_encode(['id' => $order->purchaseId]);
  1006. // $noticeKey = "ghsKdNoticeHd";
  1007. // Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
  1008. }
  1009. }
  1010. //订单生成时唤起在线打印
  1011. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  1012. //预订单开单不打小票,小向花卉不需要打小票
  1013. $mainId = $order->mainId ?? 0;
  1014. if ($order->book == 0 && !in_array($mainId, [23390])) {
  1015. if ($order->status != 1 && $order->status != 5) {
  1016. OrderClass::onlinePrint($order);
  1017. $ext = $this->shopExt;
  1018. if (isset($ext->printSn) && !empty($ext->printSn)) {
  1019. $order->printNum += 1;
  1020. $order->save();
  1021. }
  1022. }
  1023. }
  1024. }
  1025. //前台提醒出示付款码
  1026. if (isset($order->status) && $order->status == 1) {
  1027. if (isset($post['isCashier']) && $post['isCashier'] == 1) {
  1028. ShopExtClass::ghsPleasePayReport($order);
  1029. }
  1030. }
  1031. }
  1032. util::success($return);
  1033. } catch (\Exception $e) {
  1034. $transaction->rollBack();
  1035. Yii::error("下单失败原因:" . $e->getMessage());
  1036. noticeUtil::push("零售下单失败原因:" . $e->getMessage(), '15280215347');
  1037. util::fail('下单失败');
  1038. }
  1039. }
  1040. //修改订单 ssh 20210810
  1041. public function actionUpdateOrder()
  1042. {
  1043. $post = Yii::$app->request->post();
  1044. util::fail('订单不可修改');
  1045. //PC端开单
  1046. if (isset($post['clearType'])) {
  1047. $clearType = $post['clearType'];
  1048. if ($clearType == OrderClass::CLEAR_DEBT) {
  1049. $post['debt'] = OrderClass::DEBT_YES;
  1050. $post['payWay'] = dict::getDict('payWay', 'debtPay');
  1051. } else {
  1052. $post['debt'] = OrderClass::DEBT_NO;
  1053. }
  1054. }
  1055. //员工不能开已收款订单
  1056. $debt = $post['debt'] ?? OrderClass::DEBT_YES;
  1057. if ($debt == OrderClass::DEBT_NO) {
  1058. $shopAdmin = $this->shopAdmin;
  1059. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  1060. util::fail('不能开已收款订单');
  1061. }
  1062. }
  1063. //PC端开单
  1064. if (isset($post['getType'])) {
  1065. util::fail('暂不支持PC端修改订单');
  1066. $getType = $post['getType'];
  1067. //自取
  1068. if ($getType == 1) {
  1069. $post['sendType'] = OrderClass::SEND_TYPE_NO;
  1070. } else {
  1071. //选择配送时,在发货时让商家自己再确认一下用什么方式
  1072. $post['sendType'] = OrderClass::SEND_TYPE_UNKNOWN;
  1073. }
  1074. }
  1075. //商家开非自取订单,默认订单是待收款的,debt字段为非欠款
  1076. if (isset($post['sendType']) && $post['sendType'] != OrderClass::SEND_TYPE_NO) {
  1077. $post['debt'] = OrderClass::DEBT_NO;
  1078. }
  1079. $id = $post['id'] ?? 0;
  1080. $order = OrderClass::getLockById($id);
  1081. if (empty($order)) {
  1082. util::fail('没有找到订单');
  1083. }
  1084. OrderClass::valid($order, $this->shopId);
  1085. unset($post['id']);
  1086. $shopAdmin = $this->shopAdmin;
  1087. $post['shopAdminId'] = $this->shopAdminId;
  1088. $post['shopAdminName'] = $shopAdmin->name ?? '';
  1089. $post['fromType'] = 1;
  1090. $post['sendCost'] = $post['sendCost'] ?? '0.00';
  1091. $productJson = $post['product'] ?? '';
  1092. if (empty($productJson)) {
  1093. util::fail('请选择花材');
  1094. }
  1095. $productList = json_decode($productJson, true);
  1096. if (empty($productList)) {
  1097. util::fail('请选择花材');
  1098. }
  1099. $connection = Yii::$app->db;//事务处理
  1100. $transaction = $connection->beginTransaction();
  1101. try {
  1102. //判断花材有效性
  1103. ProductClass::valid($productList, $this->mainId);
  1104. $post['product'] = $productList;
  1105. //商家开单订单有效期,到期记欠款
  1106. $validTime = dict::getDict('order_pay_has_time');
  1107. $current = time() + $validTime;
  1108. $post['deadline'] = date("Y-m-d H:i:s", $current);
  1109. $upData = [
  1110. 'payWay' => $post['payWay'],
  1111. 'sendType' => $post['sendType'],
  1112. 'debt' => $post['debt'],
  1113. 'needPrint' => $post['needPrint'],
  1114. 'modifyPrice' => $post['modifyPrice'],
  1115. 'shopAdminId' => $post['shopAdminId'],
  1116. 'shopAdminName' => $post['shopAdminName'],
  1117. 'fromType' => 1,
  1118. 'sendCost' => $post['sendCost'],
  1119. 'product' => $post['product'],
  1120. 'deadline' => $post['deadline'],
  1121. 'debt' => $post['debt'],
  1122. ];
  1123. $return = OrderService::updateOrder($order, $upData);
  1124. $transaction->commit();
  1125. util::success($return);
  1126. } catch (\Exception $e) {
  1127. $transaction->rollBack();
  1128. Yii::error("下单失败原因:" . $e->getMessage());
  1129. util::fail('下单失败');
  1130. }
  1131. }
  1132. //取消预订单 ssh 20240503
  1133. public function actionCancelBookOrder()
  1134. {
  1135. $get = Yii::$app->request->get();
  1136. $id = $get['id'] ?? 0;
  1137. if (empty($id)) {
  1138. util::fail('请选择订单');
  1139. }
  1140. $order = OrderClass::getById($id, true);
  1141. if (empty($order)) {
  1142. util::fail('没有找到订单');
  1143. }
  1144. OrderClass::valid($order, $this->shopId);
  1145. if ($order->book == 0) {
  1146. util::fail('不是预订单');
  1147. }
  1148. if ($order->status != 2) {
  1149. util::fail('当前订单状态不能取消');
  1150. }
  1151. $purchaseId = $order->purchaseId ?? 0;
  1152. $purchase = PurchaseClass::getById($purchaseId, true);
  1153. if (empty($purchase)) {
  1154. util::fail('没有找到采购单');
  1155. }
  1156. $connection = Yii::$app->db;//事务处理
  1157. $transaction = $connection->beginTransaction();
  1158. try {
  1159. $order->status = 5;
  1160. $order->save();
  1161. $purchase->status = 5;
  1162. $purchase->save();
  1163. $transaction->commit();
  1164. util::complete('取消成功');
  1165. } catch (\Exception $e) {
  1166. $transaction->rollBack();
  1167. $msg = $e->getMessage();
  1168. $orderSn = $order->orderSn ?? '';
  1169. noticeUtil::push("预订单{$orderSn}取消失败:{$msg}", '15280215347');
  1170. }
  1171. }
  1172. //取消订单 shizhongqi 20220619
  1173. public function actionCancelOrder()
  1174. {
  1175. $post = Yii::$app->request->post();
  1176. $id = $post['orderId'] ?? 0;
  1177. if (empty($id)) {
  1178. util::fail('请选择订单');
  1179. }
  1180. $order = OrderClass::getById($id, true);
  1181. if (empty($order)) {
  1182. util::fail('请选择订单...');
  1183. }
  1184. OrderClass::valid($order, $this->shopId);
  1185. if (isset($order->status) == false || $order->status != 1) {
  1186. util::fail('不是待付款状态,无法取消');
  1187. }
  1188. $purchaseId = $order->purchaseId ?? 0;
  1189. $purchase = PurchaseClass::getById($purchaseId);
  1190. if (empty($purchase)) {
  1191. util::fail('没有找到采购单');
  1192. }
  1193. $deadLineTime = strtotime($purchase['deadline']);
  1194. $diff = $deadLineTime - time();
  1195. if ($diff <= 60) {
  1196. util::fail('1分钟后订单将自动取消');
  1197. }
  1198. $connection = Yii::$app->db;//事务处理
  1199. $transaction = $connection->beginTransaction();
  1200. $orderSn = $purchase['orderSn'];
  1201. try {
  1202. $current = PurchaseClass::getById($purchaseId, true);
  1203. PurchaseService::expire($current);
  1204. $transaction->commit();
  1205. //noticeUtil::push("采购单过期未付款,库存已回滚,单号:{$orderSn}");
  1206. } catch (\Exception $e) {
  1207. $transaction->rollBack();
  1208. $msg = $e->getMessage();
  1209. noticeUtil::push("采购单过期处理报错了!订单号:{$orderSn},错误信息:{$msg}", '15280215347');
  1210. }
  1211. util::complete();
  1212. }
  1213. //延期支付 ssh 2021.1.19
  1214. public function actionDebt()
  1215. {
  1216. $id = Yii::$app->request->get('id');
  1217. //4秒内不允许重复提交
  1218. $cacheKey = 'ghs_set_order_debt_' . $id;
  1219. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  1220. if (!empty($has)) {
  1221. util::fail('请稍等');
  1222. }
  1223. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 4, 'has']);
  1224. $order = OrderClass::getById($id, true);
  1225. OrderClass::valid($order, $this->shopId);
  1226. $payWay = dict::getDict('payWay', 'debtPay');
  1227. $cgId = $order->purchaseId ?? 0;
  1228. $cg = PurchaseClass::getById($cgId, true);
  1229. if (empty($cg)) {
  1230. util::fail('没有找到采购单');
  1231. }
  1232. if ($order->book == 1) {
  1233. util::fail('预订单不能记欠款');
  1234. }
  1235. $connection = Yii::$app->db;
  1236. $transaction = $connection->beginTransaction();
  1237. try {
  1238. PurchaseService::payAfter($cg, $payWay);
  1239. OrderService::payAfter($order, $payWay);
  1240. $transaction->commit();
  1241. } catch (\Exception $exception) {
  1242. $transaction->rollBack();
  1243. Yii::info("延期支付报错:" . $exception->getMessage());
  1244. util::fail('操作失败');
  1245. }
  1246. $order = OrderClass::getById($id, true);
  1247. if (!empty($order)) {
  1248. $shopId = $order->shopId ?? 0;
  1249. $shop = ShopClass::getById($shopId, true);
  1250. if (!empty($shop)) {
  1251. //花店采购供货商端微信收到通知
  1252. //WxMessageClass::ghsHasNewOrderInform($shop, $order);
  1253. $noticeText = json_encode(['orderId' => $id]);
  1254. $noticeKey = "hdCgNoticeGhs";
  1255. Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
  1256. }
  1257. //订单生成时唤起在线打印
  1258. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  1259. if ($order->status != 1 && $order->status != 5) {
  1260. OrderClass::onlinePrint($order);
  1261. $ext = $this->shopExt;
  1262. if (isset($ext->printSn) && !empty($ext->printSn)) {
  1263. $order->printNum += 1;
  1264. $order->save();
  1265. }
  1266. }
  1267. }
  1268. if ($order->status != 1 && $order->status != 5) {
  1269. //花店采购供货商端APP收到通知
  1270. //NoticeClass::ghsNewOrderNotice($order);
  1271. }
  1272. }
  1273. util::complete();
  1274. }
  1275. //获取商城下单要用的微信支付和小程序支付参数 ssh 2019.21.3
  1276. public function actionWxPay()
  1277. {
  1278. ini_set('date.timezone', 'Asia/Shanghai');
  1279. $post = Yii::$app->request->post();
  1280. $couponId = $post['couponId'] ?? 0;
  1281. $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
  1282. $order = OrderClass::getByOrderSn($orderSn);
  1283. if (empty($order)) {
  1284. util::fail('订单号无效');
  1285. }
  1286. $id = $order['id'];
  1287. //支付前验证订单有效性
  1288. if (isset($order['adminId']) == false || $order['adminId'] != $this->adminId) {
  1289. util::fail('无法操作');
  1290. }
  1291. $name = $order['orderName'] ?? '购买商品';
  1292. $totalFee = $order['actPrice'];
  1293. //强制使用小程序的miniOpenId
  1294. $openId = isset($this->admin) && !empty($this->admin) ? $this->admin->miniOpenId : '';
  1295. if (empty($openId)) {
  1296. util::fail('没有找到openId');
  1297. }
  1298. $capitalType = dict::getDict('capitalType', 'xhGhsOrder', 'id');
  1299. //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
  1300. $wxPayType = 0;
  1301. if (httpUtil::isMiniProgram()) {
  1302. $wxPayType = 1;
  1303. }
  1304. $attach = "couponId=" . $couponId . "&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType;
  1305. //订单30分钟后过期
  1306. $now = time();
  1307. $expireTime = $now + 1800;
  1308. $wx = Yii::getAlias("@vendor/weixin");
  1309. require_once($wx . '/lib/WxPay.Api.php');
  1310. require_once($wx . '/example/WxPay.JsApiPay.php');
  1311. $input = new \WxPayUnifiedOrder();
  1312. $input->SetBody($name);
  1313. $input->SetOut_trade_no($orderSn);
  1314. $input->SetTotal_fee($totalFee * 100);
  1315. $input->SetTime_start(date("YmdHis", $now));
  1316. $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
  1317. $input->SetTime_expire(date("YmdHis", $expireTime));
  1318. $input->SetNotify_url(Yii::$app->params['ghsHost'] . '/notice/wx-callback/');
  1319. $input->SetTrade_type("JSAPI");
  1320. //花卉宝代为申请的微信支付
  1321. //$sjExtend = $this->sjExtend->attributes;
  1322. $sjExtend = WxOpenClass::getGhsWxInfo();
  1323. if (isset($sjExtend['wxPayApply']) && $sjExtend['wxPayApply'] == 1) {
  1324. $input->SetSub_openid($openId);
  1325. } else {
  1326. $input->SetOpenid($openId);
  1327. }
  1328. //强制使用小程序的miniAppId
  1329. $sjExtend['wxAppId'] = $sjExtend['miniAppId'];
  1330. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $sjExtend);
  1331. $tools = new \JsApiPay();
  1332. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $sjExtend);
  1333. $newParams = json_decode($jsApiParameters, true);
  1334. //微信不能修改价格
  1335. $current = date("Y-m-d H:i:s");
  1336. $updateData = ['deadline' => $current, 'modPrice' => 0];
  1337. OrderClass::updateById($id, $updateData);
  1338. util::success($newParams);
  1339. }
  1340. //获取订单详情 ssh 2021.1.21
  1341. public function actionDetail()
  1342. {
  1343. $get = Yii::$app->request->get();
  1344. $id = $get['id'] ?? 0;
  1345. $info = OrderService::getOrderInfo($id, true, true, true, false);
  1346. OrderClass::valid($info, $this->shopId);
  1347. //A4打印需要用到的数据
  1348. $customId = $info['customId'] ?? 0;
  1349. $remark = $info['remark'] ?? '';
  1350. $sendCost = $info['sendCost'] ?? 0;
  1351. $sendNum = $info['sendNum'] ?? '';
  1352. $packCost = $info['packCost'] ?? 0;
  1353. $staffName = $info['shopAdminName'] ?? '';
  1354. $ysName = '';
  1355. if (isset($info['localOrder']) && $info['localOrder'] == 1) {
  1356. if ($info['transType'] == 0) {
  1357. $ysName = '德邦空运';
  1358. }
  1359. if ($info['transType'] == 1) {
  1360. $ysName = '顺丰空运';
  1361. }
  1362. if ($info['transType'] == 2) {
  1363. $ysName = '冷链物流';
  1364. }
  1365. if ($info['transType'] == 3) {
  1366. $ysName = '航空物流';
  1367. }
  1368. if ($info['transType'] == 4) {
  1369. $ysName = '同城配送';
  1370. }
  1371. if ($info['transType'] == 5) {
  1372. $ysName = '到店自取';
  1373. }
  1374. } else {
  1375. }
  1376. $fullAddress = '';
  1377. if (getenv('YII_ENV') == 'production') {
  1378. //老油的要显示地址
  1379. if ($this->mainId == 20528) {
  1380. $fullAddress = $info['fullAddress'] ?? '';
  1381. }
  1382. } else {
  1383. if ($this->mainId == 644) {
  1384. $fullAddress = $info['fullAddress'] ?? '';
  1385. }
  1386. }
  1387. $custom = CustomClass::getById($customId, true);
  1388. if (empty($custom)) {
  1389. util::fail('没有找到客户');
  1390. }
  1391. $customName = $custom->name ?? '';
  1392. $customMobile = $custom->customMobile ?? '';
  1393. if (empty($customMobile)) {
  1394. $customShopId = $custom->shopId ?? 0;
  1395. $customShop = ShopClass::getById($customShopId, true);
  1396. if (!empty($customShop)) {
  1397. $customMobile = $customShop->mobile ?? '';
  1398. }
  1399. }
  1400. if (!empty($customMobile)) {
  1401. $customMobile = substr_replace($customMobile, '****', 3, 4);
  1402. }
  1403. $fullCustom = $customName . ' ' . $customMobile;
  1404. if ($this->mainId == 8164) {
  1405. //花大苪不显示客户名称
  1406. $fullCustom = '';
  1407. }
  1408. $seatSn = isset($custom->seatSn) && !empty($custom->seatSn) ? $custom->seatSn : '无';
  1409. $sendTimeWant = $info['sendTimeWant'] ?? '';
  1410. $shortSendTimeWant = !empty($sendTimeWant) ? substr($sendTimeWant, 5, 5) : '';
  1411. $totalItemNum = 0;
  1412. $totalSmallItemNum = 0;
  1413. $table = [];
  1414. if (isset($info['product']) && !empty($info['product'])) {
  1415. foreach ($info['product'] as $key => $val) {
  1416. $currentName = $val['name'] ?? '';
  1417. $num = $val['xhNum'] ?? 0;
  1418. $refundNum = $val['refundNum'] ?? 0;
  1419. $num = bcsub($num, $refundNum);
  1420. $totalItemNum = bcadd($totalItemNum, $num);
  1421. $ratio = $val['ratio'] ?? 0;
  1422. $currentSmallNum = bcmul($num, $ratio);
  1423. $totalSmallItemNum = bcadd($totalSmallItemNum, $currentSmallNum);
  1424. $itemRemark = $val['remark'] ?? '';
  1425. $table[] = [
  1426. 'name' => $currentName,
  1427. 'num' => $num,
  1428. 'confirmNum' => '',
  1429. 'remark' => $itemRemark,
  1430. 'wxNumber' => 'shish3508',
  1431. ];
  1432. }
  1433. }
  1434. $shop = $this->shop;
  1435. $sjName = $shop->merchantName ?? '';
  1436. $shopName = $shop->shopName ?? '';
  1437. $sjShopName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  1438. $a4Print = [
  1439. 'customName' => $fullCustom,
  1440. 'staffName' => $staffName,
  1441. 'seatSn' => $seatSn,
  1442. 'shortSendTimeWant' => $shortSendTimeWant,
  1443. 'table' => $table,
  1444. 'remark' => $remark,
  1445. 'fullAddress' => $fullAddress,
  1446. 'sendNum' => $sendNum,
  1447. 'sendCost' => $sendCost,
  1448. 'ysName' => $ysName,
  1449. 'packCost' => $packCost,
  1450. 'totalItemNum' => $totalItemNum,
  1451. 'totalSmallItemNum' => $totalSmallItemNum,
  1452. 'shopName' => $sjShopName . ' 销售单',
  1453. ];
  1454. $info['printData'] = $a4Print;
  1455. //打印模板
  1456. $template = '{"panels":[{"index":0,"name":1,"height":297,"width":210,"paperHeader":49.5,"paperFooter":780,"printElements":[{"options":{"left":30,"top":53,"height":52,"width":538,"field":"table","coordinateSync":false,"widthHeightSync":false,"fontSize":16,"lineHeight":30,"tableBorder":"border","tableHeaderBorder":"border","tableHeaderCellBorder":"border","tableHeaderFontWeight":"bold","right":567.25,"bottom":110.24609375,"vCenter":298.25,"hCenter":82.24609375,"textAlign":"center","columns":[[{"width":188.91632245461145,"title":"名称","field":"name","checked":true,"columnId":"name","fixed":false,"rowspan":1,"colspan":1,"align":"center","halign":"center","vAlign":"middle","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":105.15171514242958,"title":"预订数","field":"num","checked":true,"columnId":"num","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":103.08801880877742,"title":"确认数","field":"confirmNum","checked":true,"columnId":"confirmNum","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":140.84394359418155,"title":"备注","field":"remark","checked":true,"columnId":"remark","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":93.32065807548679,"title":"日期","field":"shortTime","checked":false,"columnId":"shortTime","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":74.09275968851016,"title":"库存","field":"stock","checked":false,"columnId":"stock","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":276,"title":"金额\n","field":"amount","checked":false,"columnId":"amount","fixed":false,"rowspan":1,"colspan":1,"tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":100,"title":"","field":"","checked":false,"columnId":"","fixed":false,"rowspan":1,"colspan":1},{"width":100,"title":"","field":"","checked":false,"columnId":"","fixed":false,"rowspan":1,"colspan":1}]]},"printElementType":{"title":"空白表格","type":"table","editable":true,"columnDisplayEditable":true,"columnDisplayIndexEditable":true,"columnTitleEditable":true,"columnResizable":true,"columnAlignEditable":true,"isEnableEditField":true,"isEnableContextMenu":true,"isEnableInsertRow":true,"isEnableDeleteRow":true,"isEnableInsertColumn":true,"isEnableDeleteColumn":true,"isEnableMergeCell":true}},{"options":{"left":12,"top":786,"height":49,"width":49},"printElementType":{"title":"html","type":"html"}},{"options":{"left":392.5,"top":785,"height":13,"width":199,"title":"销花宝提供技术支持","textAlign":"center","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"right":590.74609375,"bottom":801.25,"vCenter":491.24609375,"hCenter":794.75},"printElementType":{"title":"自定义文本","type":"text"}},{"options":{"left":335,"top":12.5,"height":44,"width":233,"title":"货号","field":"seatSn","testData":"60","coordinateSync":false,"widthHeightSync":false,"fontSize":20,"fontWeight":"bold","textAlign":"right","textContentVerticalAlign":"middle","qrCodeLevel":0,"right":567.9921875,"bottom":51.2421875,"vCenter":451.4921875,"hCenter":29.2421875},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":12.5,"height":46,"width":128,"title":"12-16","right":147.75,"bottom":49.49609375,"vCenter":87.75,"hCenter":28.99609375,"field":"shortSendTimeWant","testData":"12-16","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":20,"fontWeight":"bold","textContentVerticalAlign":"middle","qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":95,"top":17.5,"height":35,"width":373,"title":"文本","right":469,"bottom":52.49609375,"vCenter":282.5,"hCenter":34.99609375,"field":"customName","testData":"纯彩 15280215347","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":14,"fontWeight":"bold","textAlign":"center","textContentVerticalAlign":"middle","qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":32.5,"top":377.5,"height":200,"width":535,"title":"备注","right":571.4921875,"bottom":550.25,"vCenter":303.9921875,"hCenter":450.25,"field":"remark","testData":"箱子上要写上姓名和电话,到货时要拆箱,检查里面的花材","coordinateSync":false,"widthHeightSync":false,"fontSize":20,"fontWeight":"bold","lineHeight":30,"qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":32.5,"top":302.5,"height":70,"width":536,"title":"地址","field":"fullAddress","testData":"福建省厦门市集美区前山路147号中华人民共和国福建省厦门市集美区前山路147号中华人民共和国","coordinateSync":false,"widthHeightSync":false,"fontSize":18,"fontWeight":"bold","qrCodeLevel":0,"right":561.2421875,"bottom":616.75,"vCenter":293.2421875,"hCenter":581.75,"lineHeight":32.25},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":200,"height":50,"width":400,"title":"编号","field":"sendNum","testData":"39","coordinateSync":false,"widthHeightSync":false,"fontSize":20,"lineHeight":36,"qrCodeLevel":0,"right":430,"bottom":284.99609375,"vCenter":230,"hCenter":259.99609375},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":32.5,"top":257.5,"height":39,"width":240,"title":"运费","field":"sendCost","testData":"0","coordinateSync":false,"widthHeightSync":false,"fontSize":20,"lineHeight":28.5,"qrCodeLevel":0,"right":526.7421875,"bottom":415.74609375,"vCenter":276.7421875,"hCenter":400.74609375},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":295,"top":202.5,"height":43,"width":270,"title":"德邦物流","right":565.74609375,"bottom":280.99609375,"vCenter":430.74609375,"hCenter":259.49609375,"field":"ysName","testData":"德邦物流","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":20,"lineHeight":36,"qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":297.5,"top":260,"height":41,"width":260,"title":"打包费","field":"packCost","testData":"30","coordinateSync":false,"widthHeightSync":false,"fontSize":20,"lineHeight":24,"qrCodeLevel":0,"right":555.74609375,"bottom":332.99609375,"vCenter":425.74609375,"hCenter":312.49609375},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":160,"height":36,"width":189,"title":"花材数量","field":"totalItemNum","testData":"20","coordinateSync":false,"widthHeightSync":false,"fontFamily":"cursive","fontSize":24,"fontWeight":"bold","lineHeight":32.25,"qrCodeLevel":0,"right":219,"bottom":158.49609375,"vCenter":124.5,"hCenter":140.49609375},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":295,"top":160,"height":36,"width":189,"title":"支数","field":"totalSmallItemNum","testData":"600","coordinateSync":false,"widthHeightSync":false,"fontFamily":"cursive","fontSize":24,"fontWeight":"bold","lineHeight":32.25,"qrCodeLevel":0,"right":482.25,"bottom":195.24609375,"vCenter":387.75,"hCenter":177.24609375},"printElementType":{"title":"文本","type":"text"}}],"paperNumberLeft":565.5,"paperNumberTop":819,"paperNumberContinue":true,"watermarkOptions":{"content":"vue-plugin-hiprint","rotate":25,"timestamp":true,"format":"YYYY-MM-DD HH:mm"},"panelLayoutOptions":{}}]}';
  1457. if (getenv('YII_ENV') == 'production') {
  1458. if (in_array($this->mainId, [23390, 50])) {
  1459. $template = '{"panels":[{"index":0,"name":1,"height":297,"width":210,"paperHeader":49.5,"paperFooter":780,"printElements":[{"options":{"left":30,"top":53,"height":52,"width":538,"field":"table","coordinateSync":false,"widthHeightSync":false,"tableBorder":"border","tableHeaderBorder":"border","tableHeaderCellBorder":"border","tableHeaderFontWeight":"bold","right":567.25,"bottom":110.24609375,"vCenter":298.25,"hCenter":82.24609375,"textAlign":"center","columns":[[{"width":188.91632245461145,"title":"名称","field":"name","checked":true,"columnId":"name","fixed":false,"rowspan":1,"colspan":1,"align":"center","halign":"center","vAlign":"middle","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":105.15171514242958,"title":"预订数","field":"num","checked":true,"columnId":"num","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":103.08801880877742,"title":"确认数","field":"confirmNum","checked":true,"columnId":"confirmNum","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":140.84394359418155,"title":"备注","field":"remark","checked":true,"columnId":"remark","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":93.32065807548679,"title":"日期","field":"shortTime","checked":false,"columnId":"shortTime","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":74.09275968851016,"title":"库存","field":"stock","checked":false,"columnId":"stock","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":276,"title":"金额\n","field":"amount","checked":false,"columnId":"amount","fixed":false,"rowspan":1,"colspan":1,"tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":100,"title":"","field":"","checked":false,"columnId":"","fixed":false,"rowspan":1,"colspan":1},{"width":100,"title":"","field":"","checked":false,"columnId":"","fixed":false,"rowspan":1,"colspan":1}]]},"printElementType":{"title":"空白表格","type":"table","editable":true,"columnDisplayEditable":true,"columnDisplayIndexEditable":true,"columnTitleEditable":true,"columnResizable":true,"columnAlignEditable":true,"isEnableEditField":true,"isEnableContextMenu":true,"isEnableInsertRow":true,"isEnableDeleteRow":true,"isEnableInsertColumn":true,"isEnableDeleteColumn":true,"isEnableMergeCell":true}},{"options":{"left":12,"top":786,"height":49,"width":49},"printElementType":{"title":"html","type":"html"}},{"options":{"left":382.5,"top":785,"height":13,"width":136,"title":"销花宝提供技术支持","textAlign":"center","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"right":518.74609375,"bottom":801.49609375,"vCenter":450.74609375,"hCenter":794.99609375},"printElementType":{"title":"自定义文本","type":"text"}},{"options":{"left":332.5,"top":35,"height":19,"width":233,"title":"货号","field":"seatSn","testData":"60","coordinateSync":false,"widthHeightSync":false,"fontSize":12,"fontWeight":"bold","textAlign":"right","textContentVerticalAlign":"middle","qrCodeLevel":0,"right":567.9921875,"bottom":51.2421875,"vCenter":451.4921875,"hCenter":29.2421875},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":32.5,"height":19,"width":128,"title":"12-16","right":147.75,"bottom":49.49609375,"vCenter":87.75,"hCenter":28.99609375,"field":"shortSendTimeWant","testData":"12-16","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":12,"fontWeight":"bold","textContentVerticalAlign":"middle","qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":92.5,"top":32.5,"height":19,"width":411,"title":"文本","right":469,"bottom":52.49609375,"vCenter":282.5,"hCenter":34.99609375,"field":"customName","testData":"纯彩 15280215347","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":11,"fontWeight":"bold","textAlign":"center","textContentVerticalAlign":"middle","qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":145,"height":45,"width":535,"title":"备注","right":559.24609375,"bottom":207.99609375,"vCenter":291.74609375,"hCenter":185.49609375,"field":"remark","testData":"箱子上要写上姓名和电话,到货时要拆箱,检查里面的花材","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"fontWeight":"bold","lineHeight":30,"qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":107.5,"height":30,"width":536,"title":"地址","field":"fullAddress","testData":"福建省厦门市集美区前山路147号中华人民共和国福建省厦门市集美区前山路147号中华人民共和国","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"right":561.2421875,"bottom":616.75,"vCenter":293.2421875,"hCenter":581.75,"lineHeight":32.25},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":135,"height":15,"width":52,"title":"编号","field":"sendNum","testData":"39","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"right":241.99609375,"bottom":182.49609375,"vCenter":215.99609375,"hCenter":174.99609375},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":95,"top":135,"height":15,"width":79,"title":"德邦物流","right":174.25,"bottom":159.24609375,"vCenter":134.75,"hCenter":151.74609375,"field":"ysName","testData":"德邦物流","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":177.5,"top":137.5,"height":9.75,"width":120,"title":"开单人","field":"staffName","testData":"石头","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"right":298.9921875,"bottom":154.74609375,"vCenter":238.9921875,"hCenter":149.87109375},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":297.5,"top":137.5,"height":9.75,"width":120,"title":"打包人","field":"packName","testData":"小林","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"right":417.24609375,"bottom":157.2421875,"vCenter":357.24609375,"hCenter":152.3671875},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":92.5,"top":7.5,"height":25,"width":411,"title":"文本","right":509.74609375,"bottom":35.99609375,"vCenter":309.74609375,"hCenter":24.49609375,"field":"shopName","testData":"小向花卉 销售单","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":16,"fontWeight":"bold","textAlign":"center","textContentVerticalAlign":"middle","qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}}],"paperNumberLeft":552.5,"paperNumberTop":785,"paperNumberContinue":true,"fontFamily":"Microsoft YaHei","watermarkOptions":{"content":"","rotate":25,"timestamp":false,"format":"YYYY-MM-DD HH:mm","fillStyle":"rgba(184, 184, 184, 0.3)","fontSize":"14px","width":200,"height":200},"panelLayoutOptions":{"layoutType":"column","layoutRowGap":0,"layoutColumnGap":0}}]}';
  1460. }
  1461. } else {
  1462. if (in_array($this->mainId, [644])) {
  1463. $template = '{"panels":[{"index":0,"name":1,"height":297,"width":210,"paperHeader":49.5,"paperFooter":780,"printElements":[{"options":{"left":30,"top":53,"height":52,"width":538,"field":"table","coordinateSync":false,"widthHeightSync":false,"tableBorder":"border","tableHeaderBorder":"border","tableHeaderCellBorder":"border","tableHeaderFontWeight":"bold","right":567.25,"bottom":110.24609375,"vCenter":298.25,"hCenter":82.24609375,"textAlign":"center","columns":[[{"width":188.91632245461145,"title":"名称","field":"name","checked":true,"columnId":"name","fixed":false,"rowspan":1,"colspan":1,"align":"center","halign":"center","vAlign":"middle","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":105.15171514242958,"title":"预订数","field":"num","checked":true,"columnId":"num","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":103.08801880877742,"title":"确认数","field":"confirmNum","checked":true,"columnId":"confirmNum","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":140.84394359418155,"title":"备注","field":"remark","checked":true,"columnId":"remark","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":93.32065807548679,"title":"日期","field":"shortTime","checked":false,"columnId":"shortTime","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":74.09275968851016,"title":"库存","field":"stock","checked":false,"columnId":"stock","fixed":false,"rowspan":1,"colspan":1,"align":"center","tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":276,"title":"金额\n","field":"amount","checked":false,"columnId":"amount","fixed":false,"rowspan":1,"colspan":1,"tableQRCodeLevel":0,"tableSummaryTitle":true,"tableSummary":""},{"width":100,"title":"","field":"","checked":false,"columnId":"","fixed":false,"rowspan":1,"colspan":1},{"width":100,"title":"","field":"","checked":false,"columnId":"","fixed":false,"rowspan":1,"colspan":1}]]},"printElementType":{"title":"空白表格","type":"table","editable":true,"columnDisplayEditable":true,"columnDisplayIndexEditable":true,"columnTitleEditable":true,"columnResizable":true,"columnAlignEditable":true,"isEnableEditField":true,"isEnableContextMenu":true,"isEnableInsertRow":true,"isEnableDeleteRow":true,"isEnableInsertColumn":true,"isEnableDeleteColumn":true,"isEnableMergeCell":true}},{"options":{"left":12,"top":786,"height":49,"width":49},"printElementType":{"title":"html","type":"html"}},{"options":{"left":382.5,"top":785,"height":13,"width":136,"title":"销花宝提供技术支持","textAlign":"center","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"right":518.74609375,"bottom":801.49609375,"vCenter":450.74609375,"hCenter":794.99609375},"printElementType":{"title":"自定义文本","type":"text"}},{"options":{"left":332.5,"top":35,"height":19,"width":233,"title":"货号","field":"seatSn","testData":"60","coordinateSync":false,"widthHeightSync":false,"fontSize":12,"fontWeight":"bold","textAlign":"right","textContentVerticalAlign":"middle","qrCodeLevel":0,"right":567.9921875,"bottom":51.2421875,"vCenter":451.4921875,"hCenter":29.2421875},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":32.5,"height":19,"width":128,"title":"12-16","right":147.75,"bottom":49.49609375,"vCenter":87.75,"hCenter":28.99609375,"field":"shortSendTimeWant","testData":"12-16","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":12,"fontWeight":"bold","textContentVerticalAlign":"middle","qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":92.5,"top":32.5,"height":19,"width":411,"title":"文本","right":469,"bottom":52.49609375,"vCenter":282.5,"hCenter":34.99609375,"field":"customName","testData":"纯彩 15280215347","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":11,"fontWeight":"bold","textAlign":"center","textContentVerticalAlign":"middle","qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":145,"height":45,"width":535,"title":"备注","right":559.24609375,"bottom":207.99609375,"vCenter":291.74609375,"hCenter":185.49609375,"field":"remark","testData":"箱子上要写上姓名和电话,到货时要拆箱,检查里面的花材","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"fontWeight":"bold","lineHeight":30,"qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":107.5,"height":30,"width":536,"title":"地址","field":"fullAddress","testData":"福建省厦门市集美区前山路147号中华人民共和国福建省厦门市集美区前山路147号中华人民共和国","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"right":561.2421875,"bottom":616.75,"vCenter":293.2421875,"hCenter":581.75,"lineHeight":32.25},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":30,"top":135,"height":15,"width":52,"title":"编号","field":"sendNum","testData":"39","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"right":241.99609375,"bottom":182.49609375,"vCenter":215.99609375,"hCenter":174.99609375},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":95,"top":135,"height":15,"width":79,"title":"德邦物流","right":174.25,"bottom":159.24609375,"vCenter":134.75,"hCenter":151.74609375,"field":"ysName","testData":"德邦物流","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":177.5,"top":137.5,"height":9.75,"width":120,"title":"开单人","field":"staffName","testData":"石头","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"right":298.9921875,"bottom":154.74609375,"vCenter":238.9921875,"hCenter":149.87109375},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":297.5,"top":137.5,"height":9.75,"width":120,"title":"打包人","field":"packName","testData":"小林","coordinateSync":false,"widthHeightSync":false,"qrCodeLevel":0,"right":417.24609375,"bottom":157.2421875,"vCenter":357.24609375,"hCenter":152.3671875},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":92.5,"top":7.5,"height":25,"width":411,"title":"文本","right":509.74609375,"bottom":35.99609375,"vCenter":309.74609375,"hCenter":24.49609375,"field":"shopName","testData":"小向花卉 销售单","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":16,"fontWeight":"bold","textAlign":"center","textContentVerticalAlign":"middle","qrCodeLevel":0},"printElementType":{"title":"文本","type":"text"}}],"paperNumberLeft":552.5,"paperNumberTop":785,"paperNumberContinue":true,"fontFamily":"Microsoft YaHei","watermarkOptions":{"content":"","rotate":25,"timestamp":false,"format":"YYYY-MM-DD HH:mm","fillStyle":"rgba(184, 184, 184, 0.3)","fontSize":"14px","width":200,"height":200},"panelLayoutOptions":{"layoutType":"column","layoutRowGap":0,"layoutColumnGap":0}}]}';
  1464. }
  1465. }
  1466. $info['template'] = $template;
  1467. //是否有云打印判断
  1468. $hasCloudPrint = 0;
  1469. $shopExt = $this->shopExt;
  1470. if (isset($shopExt->printSn) && !empty($shopExt->printSn) && isset($shopExt->printKey) && !empty($shopExt->printKey)) {
  1471. $hasCloudPrint = 1;
  1472. }
  1473. $info['hasCloudPrint'] = $hasCloudPrint;
  1474. $purchaseId = $info['purchaseId'] ?? 0;
  1475. $cg = PurchaseClass::getById($purchaseId);
  1476. $info['cgInfo'] = $cg;
  1477. //店长信息
  1478. $mainId = $cg['mainId'] ?? 0;
  1479. $superInfo = ShopAdminClass::getManager($mainId);
  1480. $info['customSuper'] = $superInfo;
  1481. util::success($info);
  1482. }
  1483. //获取订单信息 ssh 20240102
  1484. public function actionGetInfoByOrderSn()
  1485. {
  1486. $get = Yii::$app->request->get();
  1487. $orderSn = $get['orderSn'] ?? '';
  1488. $info = OrderService::getByCondition(['orderSn' => $orderSn], true);
  1489. if (empty($info)) {
  1490. util::fail('没有找到订单');
  1491. }
  1492. if ($info->mainId != $this->mainId) {
  1493. util::fail('不是你的订单哦');
  1494. }
  1495. util::success(['info' => $info]);
  1496. }
  1497. //获取订单详情,不需要登录可以访问,后面要删除此方法 ssh 20220819
  1498. public function actionInfo()
  1499. {
  1500. $get = Yii::$app->request->get();
  1501. $id = $get['id'] ?? 0;
  1502. $info = OrderService::getOrderInfo($id, true, true, true, false);
  1503. if (empty($info)) {
  1504. util::fail('没有找到订单');
  1505. }
  1506. //是否有云打印判断
  1507. $hasCloudPrint = 0;
  1508. $shopExt = $this->shopExt;
  1509. if (isset($shopExt->printSn) && !empty($shopExt->printSn) && isset($shopExt->printKey) && !empty($shopExt->printKey)) {
  1510. $hasCloudPrint = 1;
  1511. }
  1512. $info['hasCloudPrint'] = $hasCloudPrint;
  1513. $purchaseId = $info['purchaseId'] ?? 0;
  1514. $cg = PurchaseClass::getById($purchaseId);
  1515. $info['cgInfo'] = $cg;
  1516. //店长信息
  1517. $mainId = $cg['mainId'] ?? 0;
  1518. $superInfo = ShopAdminClass::getManager($mainId);
  1519. $info['customSuper'] = $superInfo;
  1520. util::success($info);
  1521. }
  1522. //自取免发货流程处理 ssh 2021.1.22
  1523. public function actionWithoutSend()
  1524. {
  1525. util::complete();
  1526. }
  1527. //本店送 ssh 2021.1.24
  1528. public function actionSelfSend()
  1529. {
  1530. $get = Yii::$app->request->get();
  1531. $id = isset($get['id']) ? $get['id'] : 0;
  1532. $info = OrderClass::getById($id, true);
  1533. OrderClass::valid($info->attributes, $this->shopId);
  1534. $connection = Yii::$app->db;
  1535. $transaction = $connection->beginTransaction();
  1536. try {
  1537. OrderClass::selfSend($info);
  1538. $transaction->commit();
  1539. } catch (\Exception $exception) {
  1540. $transaction->rollBack();
  1541. Yii::info("本店送操作报错:" . $exception->getMessage());
  1542. util::fail('操作失败');
  1543. }
  1544. util::complete();
  1545. }
  1546. //运费计算 ssh 2021.1.24
  1547. public function actionFreight()
  1548. {
  1549. //2021.3.28 接入达达
  1550. $get = Yii::$app->request->get();
  1551. $post = Yii::$app->request->post();
  1552. if (empty($get)) {
  1553. $get = $post;
  1554. }
  1555. $orderId = $get['id'] ?? 0; //订单ID
  1556. $customId = $get['customId'] ?? 0;
  1557. if (empty($orderId)) {
  1558. //自定义运费
  1559. //freight::getCost();
  1560. if (empty($customId)) {
  1561. util::fail("请选择客户");
  1562. }
  1563. $customInfo = CustomClass::getById($customId);
  1564. if (empty($customInfo)) {
  1565. util::fail('没有找到客户');
  1566. }
  1567. $shop = $this->shop;
  1568. //花材信息
  1569. $productJson = $get['product'] ?? '';
  1570. // $productJson = '[{"productId":31993,"bigNum":1,"smallNum":0}]';
  1571. if (empty($productJson)) {
  1572. util::fail('请选择花材');
  1573. }
  1574. $productList = json_decode($productJson, true);
  1575. if (empty($productList)) {
  1576. util::fail('请选择花材');
  1577. }
  1578. $productList = ProductClass::mergeItemInfo($productList);
  1579. $weight = 0;
  1580. $price = 0;
  1581. $productData = ProductClass::getProductMapData($productList);
  1582. $bigNum = 0;
  1583. foreach ($productList as $key => $val) {
  1584. $productId = $val['productId'];
  1585. $w = ProductClass::getWeight($val['productId'], $val['bigNum'], $val['smallNum']);
  1586. $bigNum += $val['bigNum'];
  1587. $weight = bcadd($w, $weight, 2);
  1588. $ratio = $productData[$productId]['ratio'] ?? 0;
  1589. //大小数量合并多少扎
  1590. $itemNum = ProductClass::mergeItemNum($val['bigNum'], $val['smallNum'], $ratio);
  1591. //售卖价格
  1592. $itemPrice = $productData[$productId]['price'] ?? 0;
  1593. //合计价格
  1594. $price = bcadd($price, bcmul($itemNum, $itemPrice, 2), 2);
  1595. }
  1596. //没有经纬度的客户运费直接返回空 ssh 20210612
  1597. if (empty($customInfo['lat']) || empty($customInfo['long'])) {
  1598. util::success(['sedCost' => '']);
  1599. }
  1600. $cost = freight::getCost($shop->lat, $shop->long, $customInfo['lat'], $customInfo['long'], $weight);
  1601. util::success(['sedCost' => $cost]);
  1602. }
  1603. $province = $get['province'] ?? '';
  1604. $city = $get['city'] ?? '';
  1605. $address = $get['address'] ?? '';
  1606. $floor = $get['floor'] ?? '';
  1607. $customName = $get['customName'] ?? '';
  1608. $customMobile = $get['customMobile'] ?? '';
  1609. $fullAddress = $province . $city . $address . $floor;
  1610. $sendTime = $get['sendTime'] ?? '';
  1611. $lat = $get['lat'] ?? '';
  1612. $lng = $get['long'] ?? '';
  1613. if (empty($lat) || empty($lng) || empty($fullAddress)) {
  1614. util::fail('请填写客户地址');
  1615. }
  1616. ini_set('date.timezone', 'Asia/Shanghai');
  1617. if (!empty($sendTime)) {
  1618. //配送时间不为空
  1619. // 预约发单时间(预约时间unix时间戳(10位),精确到分;整分钟为间隔,并且需要至少提前5分钟预约
  1620. $sendTimeInt = strtotime($sendTime);
  1621. $now = time();
  1622. $diff = $sendTimeInt - $now;
  1623. //因服务器写入时间,改为至少提前6分钟
  1624. if ($diff <= 360) {
  1625. util::fail('配送时间至少提前6分钟');
  1626. }
  1627. } else {
  1628. //默认立即发送
  1629. $sendTime = 0;
  1630. }
  1631. //更新订单表
  1632. $info = OrderService::getOrderInfo($orderId);
  1633. OrderClass::valid($info, $this->shopId);
  1634. if ($sendTime) {
  1635. $sendTime = date('Y-m-d H:i', strtotime($sendTime));
  1636. } else {
  1637. $sendTime = '0000-00-00 00:00:00';
  1638. }
  1639. $expressAddInfo = [
  1640. 'customName' => $customName,
  1641. 'customMobile' => $customMobile,
  1642. 'province' => $province,
  1643. 'city' => $city,
  1644. 'address' => $address,
  1645. 'floor' => $floor,
  1646. 'lat' => $lat,
  1647. 'long' => $lng,
  1648. 'sendTime' => $sendTime,
  1649. ];
  1650. OrderClass::updateCustomExpressInfo($orderId, $expressAddInfo);
  1651. //计算运费
  1652. $info['province'] = $province;
  1653. $info['city'] = $city;
  1654. $info['address'] = $address;
  1655. $info['floor'] = $floor;
  1656. $info['fullAddress'] = $fullAddress;
  1657. $info['lat'] = $lat;
  1658. $info['long'] = $lng;
  1659. $info['sendTime'] = $expressAddInfo['sendTime'];
  1660. $res = DadaExpressServices::queryDeliverFee($info);
  1661. util::success(['sedCost' => $res['fee']]);
  1662. }
  1663. //发快递和第三方配送 ssh 2021.1.24
  1664. public function actionThirdSend()
  1665. {
  1666. $get = Yii::$app->request->get();
  1667. $id = isset($get['id']) ? $get['id'] : 0;
  1668. $info = OrderService::getById($id, true);
  1669. OrderClass::valid($info->attributes, $this->shopId);
  1670. if (empty($info->lat) || empty($info->long) || empty($info->fullAddress)) {
  1671. util::fail('请填写客户地址');
  1672. }
  1673. $connection = Yii::$app->db;
  1674. $transaction = $connection->beginTransaction();
  1675. try {
  1676. $respond = OrderClass::thirdSend($info, $get);
  1677. $transaction->commit();
  1678. util::success($respond);
  1679. } catch (\Exception $exception) {
  1680. $transaction->rollBack();
  1681. Yii::info("发快递操作报错:" . $exception->getMessage());
  1682. util::fail('操作失败' . $exception->getMessage());
  1683. }
  1684. }
  1685. //确认送达 ssh 2021.1.24
  1686. public function actionReach()
  1687. {
  1688. $get = Yii::$app->request->get();
  1689. $id = isset($get['id']) ? $get['id'] : 0;
  1690. $info = OrderClass::getById($id, true);
  1691. OrderClass::valid($info->attributes, $this->shopId);
  1692. $connection = Yii::$app->db;
  1693. $transaction = $connection->beginTransaction();
  1694. try {
  1695. OrderService::reach($info);
  1696. $transaction->commit();
  1697. } catch (\Exception $exception) {
  1698. $transaction->rollBack();
  1699. Yii::info("送达操作报错:" . $exception->getMessage());
  1700. util::fail('操作失败');
  1701. }
  1702. util::complete();
  1703. }
  1704. //下单要用到的相关信息 ssh 2019.12.6
  1705. public function actionOrderRelate()
  1706. {
  1707. $regionTree = RegionService::tree();
  1708. $shop = $this->shop->attributes;
  1709. $freight = ['first' => 5, 'add' => 2];
  1710. $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
  1711. $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'txMapKey' => $mapKey, 'merchant' => $shop];
  1712. util::success($out);
  1713. }
  1714. //客户欠款的订单 ssh 2021.2.4
  1715. public function actionDebtList()
  1716. {
  1717. $get = Yii::$app->request->get();
  1718. $id = $get['id'] ?? 0;
  1719. $info = CustomClass::getCustom($id);
  1720. CustomClass::valid($info, $this->shopId);
  1721. $where = ['customId' => $id, 'debt' => 1];
  1722. $searchTime = $get['searchTime'] ?? '';
  1723. if (!empty($searchTime)) {
  1724. $startTime = $get['startTime'] ?? '';
  1725. $endTime = $get['endTime'] ?? '';
  1726. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  1727. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  1728. }
  1729. $list = OrderClass::getAllByCondition($where, 'addTime DESC', ['id', 'orderSn', 'actPrice', 'addTime', 'remainDebtPrice']);
  1730. $result = ['customInfo' => $info, 'list' => $list];
  1731. util::success($result);
  1732. }
  1733. //更新打印次数
  1734. public function actionAddPrintNum()
  1735. {
  1736. $id = Yii::$app->request->get('id', 0);
  1737. $order = OrderClass::getById($id, true);
  1738. OrderClass::valid($order, $this->shopId);
  1739. $order->printNum += 1;
  1740. $order->save();
  1741. util::complete();
  1742. }
  1743. //打印订单 ssh 20210714
  1744. public function actionCloudPrintOrder()
  1745. {
  1746. $get = Yii::$app->request->get();
  1747. $id = $get['id'] ?? 0;
  1748. $showPrice = $get['showPrice'] ?? 1;
  1749. $order = OrderClass::getById($id, true);
  1750. OrderClass::valid($order, $this->shopId);
  1751. if ($order->status == OrderClass::ORDER_STATUS_UN_PAY) {
  1752. util::fail('订单还没有付款');
  1753. }
  1754. if ($order->status == OrderClass::ORDER_STATUS_CANCEL) {
  1755. util::fail('订单已取消');
  1756. }
  1757. $ext = $this->shopExt;
  1758. if (isset($ext->printSn) == false || isset($ext->printKey) == false || empty($ext->printSn) || empty($ext->printKey)) {
  1759. util::success(['hasNoPrint' => 1]);
  1760. }
  1761. OrderClass::onlinePrint($order, $showPrice);
  1762. $order->printNum += 1;
  1763. $order->save();
  1764. util::complete();
  1765. }
  1766. //订单确认完成 ssh 20210809
  1767. public function actionConfirmFinish()
  1768. {
  1769. $payWay = Yii::$app->request->get('payWay', -1);
  1770. $id = Yii::$app->request->get('id', 0);
  1771. $clearType = Yii::$app->request->get('clearType', 0);
  1772. $connection = Yii::$app->db;
  1773. $transaction = $connection->beginTransaction();
  1774. try {
  1775. $order = OrderClass::getById($id, true);
  1776. OrderClass::valid($order, $this->shopId);
  1777. $purchaseId = $order->purchaseId ?? 0;
  1778. $purchase = PurchaseClass::getById($purchaseId, true);
  1779. if (empty($purchase)) {
  1780. util::fail('没有采购信息');
  1781. }
  1782. if ($clearType == 1) {
  1783. //欠款
  1784. $payWay = dict::getDict('payWay', 'debtPay');
  1785. } elseif ($clearType == 2) {
  1786. //已收款
  1787. if ($payWay == -1) {
  1788. util::fail('请选择收款方式');
  1789. }
  1790. $shopAdmin = $this->shopAdmin;
  1791. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  1792. util::fail('超管才能发起已收款');
  1793. }
  1794. } else {
  1795. util::fail('请选择结算方式');
  1796. }
  1797. //不需要打印
  1798. $order->needPrint = dict::getDict('needPrint', 'noNeed');
  1799. $order->save();
  1800. //支付
  1801. PurchaseService::payAfter($purchase, $payWay);
  1802. OrderService::payAfter($order, $payWay);
  1803. //自己送
  1804. $info = OrderClass::getById($id, true);
  1805. OrderClass::selfSend($info);
  1806. //确认送达,并且不需要微信通知
  1807. Yii::$app->params['noNeedWxNotice'] = 1;
  1808. $info = OrderClass::getById($id, true);
  1809. OrderService::reach($info);
  1810. $transaction->commit();
  1811. util::complete('操作成功');
  1812. } catch (\Exception $exception) {
  1813. $transaction->rollBack();
  1814. Yii::info("确认完成订单报错:" . $exception->getMessage());
  1815. util::fail('操作失败');
  1816. }
  1817. }
  1818. //取消订单 ssh 20220110
  1819. public function actionCancel()
  1820. {
  1821. $shopAdmin = $this->shopAdmin;
  1822. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  1823. util::fail('超管才能取消订单');
  1824. }
  1825. $id = Yii::$app->request->get('id');
  1826. $order = OrderClass::getById($id, true);
  1827. if ($order->orderType == 2) {
  1828. util::fail('客户下单,不能主动取消');
  1829. }
  1830. OrderClass::valid($order, $this->shopId);
  1831. OrderService::expire($order, true);
  1832. util::complete('已取消');
  1833. }
  1834. //获取收款语音播报地址 ssh 20211231
  1835. public function actionGetPayVoice()
  1836. {
  1837. $id = Yii::$app->request->get('id');
  1838. $order = OrderClass::getById($id, true);
  1839. $payWay = $order->payWay ?? 0;
  1840. $money = floatval($order->actPrice);
  1841. $payment = $payWay == dict::getDict('payWay', 'alipay') ? '支付宝' : '微信';
  1842. $msg = $payment . '收款' . $money . '元';
  1843. $audio = baiduAip::transfer($msg, 4, 0);
  1844. //上传到oss
  1845. $file = time() . rand(10000, 999999) . '.mp3';
  1846. $filePath = 'tmp/arrival/money/' . $file;
  1847. oss::uploadTmpAudio($filePath, $audio);
  1848. $url = Yii::$app->params['ghsImgHost'] . $filePath;
  1849. util::success(['url' => $url]);
  1850. }
  1851. //修改备注
  1852. public function actionModifyRemark()
  1853. {
  1854. $post = Yii::$app->request->post();
  1855. $id = $post['id'] ?? 0;
  1856. $remark = $post['remark'] ?? '';
  1857. $order = OrderClass::getById($id, true);
  1858. if (empty($order)) {
  1859. util::fail('没有找到订单');
  1860. }
  1861. if ($order->mainId != $this->mainId) {
  1862. util::fail('不是你的订单');
  1863. }
  1864. $cgId = $order->purchaseId ?? 0;
  1865. $cg = PurchaseClass::getById($cgId, true);
  1866. if (empty($cg)) {
  1867. util::fail('采购单没有找到');
  1868. }
  1869. $order->remark = $remark;
  1870. $order->save();
  1871. $cg->remark = $remark;
  1872. $cg->save();
  1873. util::complete('修改成功');
  1874. }
  1875. //修改订单的确认时间 ssh 20240511
  1876. public function actionModifyOrderConfirmTime()
  1877. {
  1878. $get = Yii::$app->request->get();
  1879. $id = $get['id'] ?? 0;
  1880. $date = $get['date'] ?? '';
  1881. if (empty($date)) {
  1882. util::fail('请选择日期');
  1883. }
  1884. $order = OrderClass::getById($id, true);
  1885. if (empty($order)) {
  1886. util::fail('没有找到订单');
  1887. }
  1888. if ($order->mainId != $this->mainId) {
  1889. util::fail('不是你的订单');
  1890. }
  1891. if ($order->payStatus == 0) {
  1892. util::fail('没有确认的订单');
  1893. }
  1894. $mainId = $this->mainId;
  1895. //超管或者约定的人可以修改日期
  1896. if (getenv('YII_ENV') == 'production') {
  1897. if (in_array($mainId, [23390])) {
  1898. if (!in_array($this->adminId, [24586, 23960])) {
  1899. util::fail('你不能修改哦');
  1900. }
  1901. }
  1902. } else {
  1903. if (in_array($mainId, [644])) {
  1904. if (!in_array($this->adminId, [919])) {
  1905. }
  1906. }
  1907. }
  1908. $payTime = $order->payTime;
  1909. $time = strtotime($payTime);
  1910. $after = date("H:i:s", $time);
  1911. $new = $date . ' ' . $after;
  1912. $cgId = $order->purchaseId ?? 0;
  1913. $cg = PurchaseClass::getById($cgId, true);
  1914. if (empty($cg)) {
  1915. util::fail('没有找到订单信息');
  1916. }
  1917. if (strtotime($new) > time()) {
  1918. util::fail('不能修改成未来时间');
  1919. }
  1920. $order->payTime = $new;
  1921. $order->save();
  1922. $cg->payTime = $new;
  1923. $cg->save();
  1924. util::complete('修改成功');
  1925. }
  1926. //应收款统计 ssh 20240528
  1927. public function actionAccountList()
  1928. {
  1929. $get = Yii::$app->request->get();
  1930. $mainId = $this->mainId;
  1931. $export = $get['export'] ?? 0;
  1932. $debt = isset($get['debt']) && is_numeric($get['debt']) ? $get['debt'] : -1;
  1933. $searchTime = isset($get['searchTime']) && !empty($get['searchTime']) ? $get['searchTime'] : 'today';
  1934. $startTime = $get['startTime'] ?? '';
  1935. $endTime = $get['endTime'] ?? '';
  1936. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  1937. $start = $period['startTime'];
  1938. $end = $period['endTime'];
  1939. $customList = CustomClass::getAllByCondition(['ownMainId' => $this->mainId], null, 'id,name', 'id');
  1940. $currentStartDate = date('Y-m-d', strtotime($start));
  1941. $currentEndDate = date('Y-m-d', strtotime($end));
  1942. $currentStartTime = $currentStartDate . ' 00:00:00';
  1943. $currentEndTime = $currentEndDate . ' 23:59:59';
  1944. $where = ['mainId' => $mainId];
  1945. if ($debt > -1) {
  1946. $where['debt'] = $debt;
  1947. }
  1948. $where['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
  1949. $orderList = OrderClass::getAllByCondition($where, null, '*');
  1950. $list = [];
  1951. $totalAmount = 0;
  1952. if (!empty($orderList)) {
  1953. foreach ($orderList as $orderInfo) {
  1954. $actPrice = $orderInfo['actPrice'] ?? 0;
  1955. $customId = $orderInfo['customId'] ?? 0;
  1956. $status = $orderInfo['status'] ?? 0;
  1957. $book = $orderInfo['book'] ?? 0;
  1958. if ($status == 1 || $status == 5) {
  1959. continue;
  1960. }
  1961. if ($book == 1 && $status == 2) {
  1962. continue;
  1963. }
  1964. if (isset($list[$customId])) {
  1965. $list[$customId]['amount'] = bcadd($list[$customId]['amount'], $actPrice, 2);
  1966. $list[$customId]['num'] = bcadd($list[$customId]['num'], 1);
  1967. } else {
  1968. $name = $customList[$customId] && $customList[$customId]['name'] ? $customList[$customId]['name'] : '未命名';
  1969. $list[$customId] = ['id' => $customId, 'name' => $name, 'amount' => $actPrice, 'num' => 1];
  1970. }
  1971. $totalAmount = bcadd($totalAmount, $actPrice, 2);
  1972. }
  1973. $list = array_values($list);
  1974. }
  1975. if ($export == 1) {
  1976. if (empty($list)) {
  1977. util::fail('没有数据需要导出');
  1978. }
  1979. ini_set('memory_limit', '2045M');
  1980. set_time_limit(0);
  1981. OrderClass::exportAccountList($list, $mainId);
  1982. util::stop();
  1983. }
  1984. util::success(['list' => $list, 'totalAmount' => $totalAmount]);
  1985. }
  1986. }