OrderController.php 115 KB

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