OrderController.php 110 KB

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