OrderController.php 114 KB

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