OrderController.php 116 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471
  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. $modifyPrice = $post['modifyPrice'] ?? 0;
  837. $pattern = '/^\d+(\.\d{1,2})?$/';
  838. if ($modifyPrice > 0) {
  839. if (preg_match($pattern, $modifyPrice) == false) {
  840. //容错前端
  841. util::fail('金额不能超2位小数');
  842. }
  843. }
  844. $custom = CustomClass::getCustom($customId);
  845. if (empty($custom)) {
  846. util::fail('请选客户哦');
  847. }
  848. $shopAdmin = $this->shopAdmin;
  849. $shopAdminId = $this->shopAdminId;
  850. $shopAdminName = $shopAdmin->name ?? '';
  851. //n秒内不允许重复提交,有多个地方要同步修改,关键词ghs_custom_create_order_redis
  852. $createOrderCacheKey = 'ghs_custom_create_order_' . $customId . '_' . $shopAdminId;
  853. $has = Yii::$app->redis->executeCommand('GET', [$createOrderCacheKey]);
  854. if (!empty($has)) {
  855. util::fail('已提交过,5秒后再试');
  856. }
  857. Yii::$app->redis->executeCommand('SETEX', [$createOrderCacheKey, 5, 'has']);
  858. CustomClass::valid($custom, $this->shopId);
  859. if (isset($custom['mainId']) && !empty($custom['mainId']) && $custom['mainId'] == $custom['ownMainId']) {
  860. util::fail('不能给自己开单');
  861. }
  862. $post['ghsId'] = $custom['ghsId'] ?? 0;
  863. $post['customMobile'] = $custom['mobile'] ?? '';
  864. $customName = $custom['name'] ?? '';
  865. $post['customName'] = $customName;
  866. $post['customNamePy'] = $custom['py'] ?? '';
  867. $post['customAvatar'] = $custom['shortSmallAvatar'] ?? '';
  868. $post['province'] = $custom['province'] ?? '';
  869. $post['city'] = $custom['city'] ?? '';
  870. $post['dist'] = $custom['dist'] ?? '';
  871. $post['address'] = $custom['address'] ?? '';
  872. $post['floor'] = $custom['floor'] ?? '';
  873. $post['fullAddress'] = $custom['fullAddress'] ?? '';
  874. $post['showAddress'] = $custom['showAddress'] ?? '';
  875. $post['long'] = $custom['long'] ?? '';
  876. $post['lat'] = $custom['lat'] ?? '';
  877. if (isset($post['getStaffId']) == true && !empty($post['getStaffId'])) {
  878. $getStaffName = $post['getStaffName'] ?? '';
  879. $shopAdminId = $post['getStaffId'];
  880. $shopAdminName = $getStaffName;
  881. } else {
  882. if (getenv('YII_ENV') == 'production') {
  883. //鹏诚需要选择开单人
  884. if (in_array($this->mainId, [19606])) {
  885. util::fail('请选择开单人');
  886. }
  887. } else {
  888. if (in_array($this->mainId, [])) {
  889. util::fail('请选择开单人');
  890. }
  891. }
  892. }
  893. if (getenv('YII_ENV') == 'production') {
  894. //小向花卉开单售后控制
  895. if ($this->mainId == 23390) {
  896. if (!in_array($this->adminId, [24043, 24585, 24586, 24654, 24115, 23960, 28456, 31105, 28456, 31105])) {
  897. util::fail('你不能开单哦');
  898. }
  899. }
  900. }
  901. //开单人和收款人必定是同个人
  902. $post['shopAdminId'] = $shopAdminId;
  903. $post['shopAdminName'] = $shopAdminName;
  904. $post['getStaffId'] = $shopAdminId;
  905. $post['getStaffName'] = $shopAdminName;
  906. $post['sjId'] = $this->sjId;
  907. $post['shopId'] = $shopId;
  908. $post['mainId'] = $this->mainId;
  909. $post['fromType'] = 1;
  910. $post['expressId'] = $post['expressId'] ?? 0;
  911. $book = $post['book'] ?? 0;
  912. $post['book'] = $book;
  913. $sendType = $post['sendType'] ?? 0;
  914. $transType = $post['transType'] ?? 0;
  915. $shop = $this->shop;
  916. if (isset($shop->pfLevel) && $shop->pfLevel == 1) {
  917. //昆明发往全国
  918. $sendCost = isset($post['sendCost']) && $post['sendCost'] > 0 ? $post['sendCost'] : 0;
  919. $post['sendCost'] = $sendCost;
  920. $packCost = isset($post['packCost']) && $post['packCost'] > 0 ? $post['packCost'] : 0;
  921. $post['packCost'] = $packCost;
  922. $post['transType'] = $transType;
  923. $post['localOrder'] = 1;
  924. } else {
  925. //同步配送
  926. $sendCost = isset($post['sendCost']) && $post['sendCost'] > 0 ? $post['sendCost'] : 0;
  927. if ($sendType != dict::getDict('sendType', 'thirdSend') && $sendCost > 0) {
  928. util::fail('填了运费,请选择代叫跑腿');
  929. }
  930. $post['sendCost'] = $sendCost;
  931. $post['packCost'] = isset($post['packCost']) && $post['packCost'] > 0 ? $post['packCost'] : 0;
  932. }
  933. if ($book == 1) {
  934. $bookSn = $shop->bookSn ?? 0;
  935. if (empty($bookSn)) {
  936. util::fail('请开启预订');
  937. }
  938. $post['bookSn'] = $bookSn;
  939. }
  940. $hasPay = $post['hasPay'] ?? dict::getDict('hasPay', 'unPay');
  941. $post['debt'] = OrderClass::DEBT_NO;
  942. if ($hasPay == dict::getDict('hasPay', 'debt')) {
  943. $post['debt'] = OrderClass::DEBT_YES;
  944. }
  945. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  946. if ($hasPay == dict::getDict('hasPay', 'payed')) {
  947. //util::fail('没有权限');
  948. }
  949. }
  950. //多颜色数据整理
  951. $colorItem = $post['xj'] ?? [];
  952. $newXj = [];
  953. if (!empty($colorItem)) {
  954. $colorData = json_decode($colorItem, true);
  955. if (!empty($colorData) && is_array($colorData)) {
  956. foreach ($colorData as $colorInfo) {
  957. $ptItemId = $colorInfo['ptItemId'] ?? 0;
  958. $colorList = $colorInfo['list'] ?? [];
  959. if (!empty($colorList)) {
  960. foreach ($colorList as $colorItemKey => $colorItem) {
  961. $newXj[$ptItemId][] = $colorItem;
  962. }
  963. }
  964. }
  965. }
  966. }
  967. $post['xj'] = $newXj;
  968. $productJson = $post['product'] ?? '';
  969. if (empty($productJson)) {
  970. util::fail('请选择花材');
  971. }
  972. $productList = json_decode($productJson, true);
  973. if (empty($productList)) {
  974. util::fail('请选择花材');
  975. }
  976. $dealPrice = $post['dealPrice'] ?? 0;
  977. $ids = array_unique(array_filter(array_column($productList, 'productId')));
  978. $itemInfo = ProductClass::getByIds($ids, null, 'id');
  979. if (empty($itemInfo)) {
  980. util::fail('请选择花材哦');
  981. }
  982. //判断花材有效性
  983. foreach ($itemInfo as $itemData) {
  984. if (isset($itemData['mainId']) == false || $itemData['mainId'] != $this->mainId) {
  985. util::fail('只能选择同一家的商品哈');
  986. }
  987. }
  988. //开单提交订单时,别人修改价格,暂成提交价格不是真实卖价问题解决!!
  989. if ($dealPrice == 0) {
  990. $diff = [];
  991. $priceMap = CustomClass::$levelPriceKeyMap;
  992. $addPriceMap = CustomClass::$levelAddPriceKeyMap;
  993. $level = $custom['level'] ?? 1;
  994. foreach ($productList as $currentKey => $currentProduct) {
  995. $currentPrice = $currentProduct['price'] ?? 0;
  996. $currentId = $currentProduct['productId'] ?? 0;
  997. $systemInfo = $itemInfo[$currentId] ?? [];
  998. $name = $systemInfo['name'] ?? '';
  999. $systemPrice = ProductClass::getFinalPrice($systemInfo, $level, $priceMap, $addPriceMap);
  1000. if (floatval($currentPrice) != floatval($systemPrice)) {
  1001. $diff[] = [
  1002. 'name' => $name,
  1003. 'price' => $systemPrice,
  1004. 'kdPrice' => $currentPrice,
  1005. ];
  1006. }
  1007. }
  1008. if (!empty($diff)) {
  1009. //n秒内不允许重复提交,有多个地方要同步修改,关键词ghs_custom_create_order_redis
  1010. Yii::$app->redis->executeCommand('DEL', [$createOrderCacheKey]);
  1011. util::success(['diff' => $diff, 'respondType' => 'priceError']);
  1012. }
  1013. }
  1014. if ($book == 1) {
  1015. $post['hasPay'] = 2;
  1016. $post['payWay'] = 0;
  1017. }
  1018. $historyDate = $post['historyDate'] ?? '';
  1019. if (!empty($historyDate)) {
  1020. if ($book == 1) {
  1021. util::fail('预订单不能选订单日期');
  1022. }
  1023. if ($hasPay == 0) {
  1024. util::fail('扫码付不能选订单日期');
  1025. }
  1026. if (strtotime($historyDate) > strtotime(date("Y-m-d"))) {
  1027. util::fail('订单日期只能选历史时间');
  1028. }
  1029. }
  1030. $connection = Yii::$app->db;//事务处理
  1031. $transaction = $connection->beginTransaction();
  1032. try {
  1033. $post['product'] = $productList;
  1034. //商家开单到时间会自动标记为欠款,所以360天内不过期,以保证足够时间标记欠款,具体参数查看dict local_gys_kd_auto_set_debt_time
  1035. $time = time();
  1036. $hasTime = dict::getDict('order_pay_has_time');
  1037. $totalTime = bcadd($time, $hasTime);
  1038. $post['deadline'] = date("Y-m-d H:i:s", $totalTime);
  1039. $return = OrderService::createFinishOrder($post, $custom, $hasPay);
  1040. $transaction->commit();
  1041. $saleId = $return->id ?? 0;
  1042. $order = OrderClass::getById($saleId, true);
  1043. if (!empty($order)) {
  1044. $shopId = $order->shopId ?? 0;
  1045. $customId = $order->customId ?? 0;
  1046. $ghsId = $order->ghsId ?? 0;
  1047. $custom = CustomClass::getById($customId, true);
  1048. $date = date("Y-m-d H:i:s");
  1049. if (!empty($custom)) {
  1050. $custom->recentExpend = $date;
  1051. $custom->save();
  1052. }
  1053. $ghs = GhsClass::getById($ghsId, true);
  1054. if (!empty($ghs)) {
  1055. $ghs->recentExpend = $date;
  1056. $ghs->save();
  1057. }
  1058. $shop = ShopClass::getById($shopId, true);
  1059. if (isset($order->payStatus) && $order->payStatus == 1) {
  1060. if (!empty($shop)) {
  1061. //通知员工
  1062. $noticeText = json_encode(['orderId' => $saleId]);
  1063. $noticeKey = "hdCgNoticeGhs";
  1064. Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
  1065. //通知花店
  1066. // $noticeText = json_encode(['id' => $order->purchaseId]);
  1067. // $noticeKey = "ghsKdNoticeHd";
  1068. // Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
  1069. }
  1070. }
  1071. //订单生成时唤起在线打印
  1072. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  1073. //预订单开单不打小票,小向花卉不需要打小票
  1074. $mainId = $order->mainId ?? 0;
  1075. if ($order->book == 0 && !in_array($mainId, [23390])) {
  1076. if ($order->status != 1 && $order->status != 5) {
  1077. OrderClass::onlinePrint($order);
  1078. $ext = $this->shopExt;
  1079. if (isset($ext->printSn) && !empty($ext->printSn)) {
  1080. $order->printNum += 1;
  1081. $order->save();
  1082. }
  1083. }
  1084. }
  1085. }
  1086. //前台提醒出示付款码
  1087. if (isset($order->status) && $order->status == 1) {
  1088. if (isset($post['isCashier']) && $post['isCashier'] == 1) {
  1089. ShopExtClass::ghsPleasePayReport($order);
  1090. }
  1091. }
  1092. }
  1093. util::success($return);
  1094. } catch (\Exception $e) {
  1095. $transaction->rollBack();
  1096. Yii::error("下单失败原因:" . $e->getMessage());
  1097. noticeUtil::push("零售下单失败原因:" . $e->getMessage(), '15280215347');
  1098. util::fail('下单失败');
  1099. }
  1100. }
  1101. //修改订单 ssh 20210810
  1102. public function actionUpdateOrder()
  1103. {
  1104. $post = Yii::$app->request->post();
  1105. util::fail('订单不可修改');
  1106. //PC端开单
  1107. if (isset($post['clearType'])) {
  1108. $clearType = $post['clearType'];
  1109. if ($clearType == OrderClass::CLEAR_DEBT) {
  1110. $post['debt'] = OrderClass::DEBT_YES;
  1111. $post['payWay'] = dict::getDict('payWay', 'debtPay');
  1112. } else {
  1113. $post['debt'] = OrderClass::DEBT_NO;
  1114. }
  1115. }
  1116. //员工不能开已收款订单
  1117. $debt = $post['debt'] ?? OrderClass::DEBT_YES;
  1118. if ($debt == OrderClass::DEBT_NO) {
  1119. $shopAdmin = $this->shopAdmin;
  1120. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  1121. util::fail('不能开已收款订单');
  1122. }
  1123. }
  1124. //PC端开单
  1125. if (isset($post['getType'])) {
  1126. util::fail('暂不支持PC端修改订单');
  1127. $getType = $post['getType'];
  1128. //自取
  1129. if ($getType == 1) {
  1130. $post['sendType'] = OrderClass::SEND_TYPE_NO;
  1131. } else {
  1132. //选择配送时,在发货时让商家自己再确认一下用什么方式
  1133. $post['sendType'] = OrderClass::SEND_TYPE_UNKNOWN;
  1134. }
  1135. }
  1136. //商家开非自取订单,默认订单是待收款的,debt字段为非欠款
  1137. if (isset($post['sendType']) && $post['sendType'] != OrderClass::SEND_TYPE_NO) {
  1138. $post['debt'] = OrderClass::DEBT_NO;
  1139. }
  1140. $id = $post['id'] ?? 0;
  1141. $order = OrderClass::getLockById($id);
  1142. if (empty($order)) {
  1143. util::fail('没有找到订单');
  1144. }
  1145. OrderClass::valid($order, $this->shopId);
  1146. unset($post['id']);
  1147. $shopAdmin = $this->shopAdmin;
  1148. $post['shopAdminId'] = $this->shopAdminId;
  1149. $post['shopAdminName'] = $shopAdmin->name ?? '';
  1150. $post['fromType'] = 1;
  1151. $post['sendCost'] = $post['sendCost'] ?? '0.00';
  1152. $productJson = $post['product'] ?? '';
  1153. if (empty($productJson)) {
  1154. util::fail('请选择花材');
  1155. }
  1156. $productList = json_decode($productJson, true);
  1157. if (empty($productList)) {
  1158. util::fail('请选择花材');
  1159. }
  1160. $connection = Yii::$app->db;//事务处理
  1161. $transaction = $connection->beginTransaction();
  1162. try {
  1163. //判断花材有效性
  1164. ProductClass::valid($productList, $this->mainId);
  1165. $post['product'] = $productList;
  1166. //商家开单订单有效期,到期记欠款
  1167. $validTime = dict::getDict('order_pay_has_time');
  1168. $current = time() + $validTime;
  1169. $post['deadline'] = date("Y-m-d H:i:s", $current);
  1170. $upData = [
  1171. 'payWay' => $post['payWay'],
  1172. 'sendType' => $post['sendType'],
  1173. 'debt' => $post['debt'],
  1174. 'needPrint' => $post['needPrint'],
  1175. 'modifyPrice' => $post['modifyPrice'],
  1176. 'shopAdminId' => $post['shopAdminId'],
  1177. 'shopAdminName' => $post['shopAdminName'],
  1178. 'fromType' => 1,
  1179. 'sendCost' => $post['sendCost'],
  1180. 'product' => $post['product'],
  1181. 'deadline' => $post['deadline'],
  1182. 'debt' => $post['debt'],
  1183. ];
  1184. $return = OrderService::updateOrder($order, $upData);
  1185. $transaction->commit();
  1186. util::success($return);
  1187. } catch (\Exception $e) {
  1188. $transaction->rollBack();
  1189. Yii::error("下单失败原因:" . $e->getMessage());
  1190. util::fail('下单失败');
  1191. }
  1192. }
  1193. //取消预订单 ssh 20240503
  1194. public function actionCancelBookOrder()
  1195. {
  1196. $get = Yii::$app->request->get();
  1197. $id = $get['id'] ?? 0;
  1198. if (empty($id)) {
  1199. util::fail('请选择订单');
  1200. }
  1201. $order = OrderClass::getById($id, true);
  1202. if (empty($order)) {
  1203. util::fail('没有找到订单');
  1204. }
  1205. OrderClass::valid($order, $this->shopId);
  1206. if ($order->book == 0) {
  1207. util::fail('不是预订单');
  1208. }
  1209. if ($order->status != 2) {
  1210. util::fail('当前订单状态不能取消');
  1211. }
  1212. $purchaseId = $order->purchaseId ?? 0;
  1213. $purchase = PurchaseClass::getById($purchaseId, true);
  1214. if (empty($purchase)) {
  1215. util::fail('没有找到采购单');
  1216. }
  1217. $connection = Yii::$app->db;//事务处理
  1218. $transaction = $connection->beginTransaction();
  1219. try {
  1220. $order->status = 5;
  1221. $order->save();
  1222. $purchase->status = 5;
  1223. $purchase->save();
  1224. $transaction->commit();
  1225. util::complete('取消成功');
  1226. } catch (\Exception $e) {
  1227. $transaction->rollBack();
  1228. $msg = $e->getMessage();
  1229. $orderSn = $order->orderSn ?? '';
  1230. noticeUtil::push("预订单{$orderSn}取消失败:{$msg}", '15280215347');
  1231. }
  1232. }
  1233. //取消订单 shizhongqi 20220619
  1234. public function actionCancelOrder()
  1235. {
  1236. $post = Yii::$app->request->post();
  1237. $id = $post['orderId'] ?? 0;
  1238. if (empty($id)) {
  1239. util::fail('请选择订单');
  1240. }
  1241. $order = OrderClass::getById($id, true);
  1242. if (empty($order)) {
  1243. util::fail('请选择订单...');
  1244. }
  1245. OrderClass::valid($order, $this->shopId);
  1246. if (isset($order->status) == false || $order->status != 1) {
  1247. util::fail('不是待付款状态,无法取消');
  1248. }
  1249. $purchaseId = $order->purchaseId ?? 0;
  1250. $purchase = PurchaseClass::getById($purchaseId);
  1251. if (empty($purchase)) {
  1252. util::fail('没有找到采购单');
  1253. }
  1254. $deadLineTime = strtotime($purchase['deadline']);
  1255. $diff = $deadLineTime - time();
  1256. if ($diff <= 60) {
  1257. util::fail('1分钟后订单将自动取消');
  1258. }
  1259. $connection = Yii::$app->db;//事务处理
  1260. $transaction = $connection->beginTransaction();
  1261. $orderSn = $purchase['orderSn'];
  1262. try {
  1263. $current = PurchaseClass::getById($purchaseId, true);
  1264. PurchaseService::expire($current);
  1265. $transaction->commit();
  1266. //noticeUtil::push("采购单过期未付款,库存已回滚,单号:{$orderSn}");
  1267. } catch (\Exception $e) {
  1268. $transaction->rollBack();
  1269. $msg = $e->getMessage();
  1270. noticeUtil::push("采购单过期处理报错了!订单号:{$orderSn},错误信息:{$msg}", '15280215347');
  1271. }
  1272. util::complete();
  1273. }
  1274. //延期支付 ssh 2021.1.19
  1275. public function actionDebt()
  1276. {
  1277. $id = Yii::$app->request->get('id');
  1278. //4秒内不允许重复提交
  1279. $cacheKey = 'ghs_set_order_debt_' . $id;
  1280. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  1281. if (!empty($has)) {
  1282. util::fail('请稍等');
  1283. }
  1284. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 4, 'has']);
  1285. $order = OrderClass::getById($id, true);
  1286. OrderClass::valid($order, $this->shopId);
  1287. $payWay = dict::getDict('payWay', 'debtPay');
  1288. $cgId = $order->purchaseId ?? 0;
  1289. $cg = PurchaseClass::getById($cgId, true);
  1290. if (empty($cg)) {
  1291. util::fail('没有找到采购单');
  1292. }
  1293. if ($order->book == 1) {
  1294. util::fail('预订单不能记欠款');
  1295. }
  1296. $connection = Yii::$app->db;
  1297. $transaction = $connection->beginTransaction();
  1298. try {
  1299. PurchaseService::payAfter($cg, $payWay);
  1300. OrderService::payAfter($order, $payWay);
  1301. $transaction->commit();
  1302. } catch (\Exception $exception) {
  1303. $transaction->rollBack();
  1304. Yii::info("延期支付报错:" . $exception->getMessage());
  1305. util::fail('操作失败');
  1306. }
  1307. $order = OrderClass::getById($id, true);
  1308. if (!empty($order)) {
  1309. $shopId = $order->shopId ?? 0;
  1310. $shop = ShopClass::getById($shopId, true);
  1311. if (!empty($shop)) {
  1312. //花店采购供货商端微信收到通知
  1313. //WxMessageClass::ghsHasNewOrderInform($shop, $order);
  1314. $noticeText = json_encode(['orderId' => $id]);
  1315. $noticeKey = "hdCgNoticeGhs";
  1316. Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
  1317. }
  1318. //订单生成时唤起在线打印
  1319. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  1320. if ($order->status != 1 && $order->status != 5) {
  1321. OrderClass::onlinePrint($order);
  1322. $ext = $this->shopExt;
  1323. if (isset($ext->printSn) && !empty($ext->printSn)) {
  1324. $order->printNum += 1;
  1325. $order->save();
  1326. }
  1327. }
  1328. }
  1329. if ($order->status != 1 && $order->status != 5) {
  1330. //花店采购供货商端APP收到通知
  1331. //NoticeClass::ghsNewOrderNotice($order);
  1332. }
  1333. }
  1334. util::complete();
  1335. }
  1336. //获取商城下单要用的微信支付和小程序支付参数 ssh 2019.21.3
  1337. public function actionWxPay()
  1338. {
  1339. ini_set('date.timezone', 'Asia/Shanghai');
  1340. $post = Yii::$app->request->post();
  1341. $couponId = $post['couponId'] ?? 0;
  1342. $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
  1343. $order = OrderClass::getByOrderSn($orderSn);
  1344. if (empty($order)) {
  1345. util::fail('订单号无效');
  1346. }
  1347. $id = $order['id'];
  1348. //支付前验证订单有效性
  1349. if (isset($order['adminId']) == false || $order['adminId'] != $this->adminId) {
  1350. util::fail('无法操作');
  1351. }
  1352. $name = $order['orderName'] ?? '购买商品';
  1353. $totalFee = $order['actPrice'];
  1354. //强制使用小程序的miniOpenId
  1355. $openId = isset($this->admin) && !empty($this->admin) ? $this->admin->miniOpenId : '';
  1356. if (empty($openId)) {
  1357. util::fail('没有找到openId');
  1358. }
  1359. $capitalType = dict::getDict('capitalType', 'xhGhsOrder', 'id');
  1360. //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
  1361. $wxPayType = 0;
  1362. if (httpUtil::isMiniProgram()) {
  1363. $wxPayType = 1;
  1364. }
  1365. $attach = "couponId=" . $couponId . "&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType;
  1366. //订单30分钟后过期
  1367. $now = time();
  1368. $expireTime = $now + 1800;
  1369. $wx = Yii::getAlias("@vendor/weixin");
  1370. require_once($wx . '/lib/WxPay.Api.php');
  1371. require_once($wx . '/example/WxPay.JsApiPay.php');
  1372. $input = new \WxPayUnifiedOrder();
  1373. $input->SetBody($name);
  1374. $input->SetOut_trade_no($orderSn);
  1375. $input->SetTotal_fee($totalFee * 100);
  1376. $input->SetTime_start(date("YmdHis", $now));
  1377. $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
  1378. $input->SetTime_expire(date("YmdHis", $expireTime));
  1379. $input->SetNotify_url(Yii::$app->params['ghsHost'] . '/notice/wx-callback/');
  1380. $input->SetTrade_type("JSAPI");
  1381. //花卉宝代为申请的微信支付
  1382. //$sjExtend = $this->sjExtend->attributes;
  1383. $sjExtend = WxOpenClass::getGhsWxInfo();
  1384. if (isset($sjExtend['wxPayApply']) && $sjExtend['wxPayApply'] == 1) {
  1385. $input->SetSub_openid($openId);
  1386. } else {
  1387. $input->SetOpenid($openId);
  1388. }
  1389. //强制使用小程序的miniAppId
  1390. $sjExtend['wxAppId'] = $sjExtend['miniAppId'];
  1391. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $sjExtend);
  1392. $tools = new \JsApiPay();
  1393. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $sjExtend);
  1394. $newParams = json_decode($jsApiParameters, true);
  1395. //微信不能修改价格
  1396. $current = date("Y-m-d H:i:s");
  1397. $updateData = ['deadline' => $current, 'modPrice' => 0];
  1398. OrderClass::updateById($id, $updateData);
  1399. util::success($newParams);
  1400. }
  1401. //获取订单详情 ssh 2021.1.21
  1402. public function actionDetail()
  1403. {
  1404. $get = Yii::$app->request->get();
  1405. $id = $get['id'] ?? 0;
  1406. $info = OrderService::getOrderInfo($id, true, true, true, false);
  1407. OrderClass::valid($info, $this->shopId);
  1408. //A4打印需要用到的数据
  1409. $customId = $info['customId'] ?? 0;
  1410. $remark = $info['remark'] ?? '';
  1411. $sendCost = $info['sendCost'] ?? 0;
  1412. $sendNum = $info['sendNum'] ?? '';
  1413. $packCost = $info['packCost'] ?? 0;
  1414. $staffName = $info['shopAdminName'] ?? '';
  1415. $ysName = '';
  1416. if (isset($info['localOrder']) && $info['localOrder'] == 1) {
  1417. if ($info['transType'] == 0) {
  1418. $ysName = '德邦空运';
  1419. }
  1420. if ($info['transType'] == 1) {
  1421. $ysName = '顺丰空运';
  1422. }
  1423. if ($info['transType'] == 2) {
  1424. $ysName = '冷链物流';
  1425. }
  1426. if ($info['transType'] == 3) {
  1427. $ysName = '航空物流';
  1428. }
  1429. if ($info['transType'] == 4) {
  1430. $ysName = '同城配送';
  1431. }
  1432. if ($info['transType'] == 5) {
  1433. $ysName = '到店自取';
  1434. }
  1435. } else {
  1436. }
  1437. $fullAddress = '';
  1438. if (getenv('YII_ENV') == 'production') {
  1439. //老油的要显示地址
  1440. if ($this->mainId == 20528) {
  1441. $fullAddress = $info['fullAddress'] ?? '';
  1442. }
  1443. } else {
  1444. if ($this->mainId == 644) {
  1445. $fullAddress = $info['fullAddress'] ?? '';
  1446. }
  1447. }
  1448. $custom = CustomClass::getById($customId, true);
  1449. if (empty($custom)) {
  1450. util::fail('没有找到客户');
  1451. }
  1452. $customName = $custom->name ?? '';
  1453. $customMobile = $custom->customMobile ?? '';
  1454. if (empty($customMobile)) {
  1455. $customShopId = $custom->shopId ?? 0;
  1456. $customShop = ShopClass::getById($customShopId, true);
  1457. if (!empty($customShop)) {
  1458. $customMobile = $customShop->mobile ?? '';
  1459. }
  1460. }
  1461. if (!empty($customMobile)) {
  1462. $customMobile = substr_replace($customMobile, '****', 3, 4);
  1463. }
  1464. $fullCustom = $customName . ' ' . $customMobile;
  1465. if ($this->mainId == 8164) {
  1466. //花大苪不显示客户名称
  1467. $fullCustom = '';
  1468. }
  1469. $seatSn = isset($custom->seatSn) && !empty($custom->seatSn) ? $custom->seatSn : '无';
  1470. $sendTimeWant = $info['sendTimeWant'] ?? '';
  1471. $shortSendTimeWant = !empty($sendTimeWant) ? substr($sendTimeWant, 5, 5) : '';
  1472. $totalItemNum = 0;
  1473. $totalSmallItemNum = 0;
  1474. $table = [];
  1475. if (isset($info['product']) && !empty($info['product'])) {
  1476. foreach ($info['product'] as $key => $val) {
  1477. $currentName = $val['name'] ?? '';
  1478. $num = $val['xhNum'] ?? 0;
  1479. $refundNum = $val['refundNum'] ?? 0;
  1480. $num = bcsub($num, $refundNum);
  1481. $totalItemNum = bcadd($totalItemNum, $num);
  1482. $ratio = $val['ratio'] ?? 0;
  1483. $currentSmallNum = bcmul($num, $ratio);
  1484. $totalSmallItemNum = bcadd($totalSmallItemNum, $currentSmallNum);
  1485. $itemRemark = $val['remark'] ?? '';
  1486. $unitPrice = $val['xhUnitPrice'] ?? 0;
  1487. $unitPrice = floatval($unitPrice);
  1488. $price = $val['xhPrice'] ?? 0;
  1489. $price = floatval($price);
  1490. $table[] = [
  1491. 'name' => $currentName,
  1492. 'num' => $num,
  1493. 'confirmNum' => '',
  1494. 'remark' => $itemRemark,
  1495. 'wxNumber' => 'shish3508',
  1496. 'unitPrice' => $unitPrice,
  1497. 'price' => $price,
  1498. ];
  1499. }
  1500. }
  1501. $shop = $this->shop;
  1502. $sjName = $shop->merchantName ?? '';
  1503. $shopName = $shop->shopName ?? '';
  1504. $sjShopName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  1505. $a4Print = [
  1506. 'customName' => $fullCustom,
  1507. 'staffName' => $staffName,
  1508. 'seatSn' => $seatSn,
  1509. 'shortSendTimeWant' => $shortSendTimeWant,
  1510. 'table' => $table,
  1511. 'remark' => $remark,
  1512. 'fullAddress' => $fullAddress,
  1513. 'sendNum' => $sendNum,
  1514. 'sendCost' => $sendCost,
  1515. 'ysName' => $ysName,
  1516. 'packCost' => $packCost,
  1517. 'totalItemNum' => $totalItemNum,
  1518. 'totalSmallItemNum' => $totalSmallItemNum,
  1519. 'shopName' => $sjShopName . ' 销售单',
  1520. ];
  1521. $info['printData'] = $a4Print;
  1522. //常规模板
  1523. $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}}]}';
  1524. if (getenv('YII_ENV') == 'production') {
  1525. //花大苪模板
  1526. if (in_array($this->mainId, [8164])) {
  1527. $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":{}}]}';
  1528. }
  1529. } else {
  1530. //测试模板
  1531. if (in_array($this->mainId, [644])) {
  1532. $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":{}}]}';
  1533. }
  1534. }
  1535. $info['template'] = $template;
  1536. //是否有云打印判断
  1537. $hasCloudPrint = 0;
  1538. $shopExt = $this->shopExt;
  1539. if (isset($shopExt->printSn) && !empty($shopExt->printSn) && isset($shopExt->printKey) && !empty($shopExt->printKey)) {
  1540. $hasCloudPrint = 1;
  1541. }
  1542. $info['hasCloudPrint'] = $hasCloudPrint;
  1543. $purchaseId = $info['purchaseId'] ?? 0;
  1544. $cg = PurchaseClass::getById($purchaseId);
  1545. $info['cgInfo'] = $cg;
  1546. //店长信息
  1547. $mainId = $cg['mainId'] ?? 0;
  1548. $superInfo = ShopAdminClass::getManager($mainId);
  1549. $info['customSuper'] = $superInfo;
  1550. util::success($info);
  1551. }
  1552. //获取订单信息 ssh 20240102
  1553. public function actionGetInfoByOrderSn()
  1554. {
  1555. $get = Yii::$app->request->get();
  1556. $orderSn = $get['orderSn'] ?? '';
  1557. $info = OrderService::getByCondition(['orderSn' => $orderSn], true);
  1558. if (empty($info)) {
  1559. util::fail('没有找到订单');
  1560. }
  1561. if ($info->mainId != $this->mainId) {
  1562. util::fail('不是你的订单哦');
  1563. }
  1564. util::success(['info' => $info]);
  1565. }
  1566. //获取订单详情,不需要登录可以访问,后面要删除此方法 ssh 20220819
  1567. public function actionInfo()
  1568. {
  1569. $get = Yii::$app->request->get();
  1570. $id = $get['id'] ?? 0;
  1571. $info = OrderService::getOrderInfo($id, true, true, true, false);
  1572. if (empty($info)) {
  1573. util::fail('没有找到订单');
  1574. }
  1575. //是否有云打印判断
  1576. $hasCloudPrint = 0;
  1577. $shopExt = $this->shopExt;
  1578. if (isset($shopExt->printSn) && !empty($shopExt->printSn) && isset($shopExt->printKey) && !empty($shopExt->printKey)) {
  1579. $hasCloudPrint = 1;
  1580. }
  1581. $info['hasCloudPrint'] = $hasCloudPrint;
  1582. $purchaseId = $info['purchaseId'] ?? 0;
  1583. $cg = PurchaseClass::getById($purchaseId);
  1584. $info['cgInfo'] = $cg;
  1585. //店长信息
  1586. $mainId = $cg['mainId'] ?? 0;
  1587. $superInfo = ShopAdminClass::getManager($mainId);
  1588. $info['customSuper'] = $superInfo;
  1589. util::success($info);
  1590. }
  1591. //自取免发货流程处理 ssh 2021.1.22
  1592. public function actionWithoutSend()
  1593. {
  1594. util::complete();
  1595. }
  1596. //本店送 ssh 2021.1.24
  1597. public function actionSelfSend()
  1598. {
  1599. $get = Yii::$app->request->get();
  1600. $id = isset($get['id']) ? $get['id'] : 0;
  1601. $info = OrderClass::getById($id, true);
  1602. OrderClass::valid($info->attributes, $this->shopId);
  1603. $connection = Yii::$app->db;
  1604. $transaction = $connection->beginTransaction();
  1605. try {
  1606. OrderClass::selfSend($info);
  1607. $transaction->commit();
  1608. } catch (\Exception $exception) {
  1609. $transaction->rollBack();
  1610. Yii::info("本店送操作报错:" . $exception->getMessage());
  1611. util::fail('操作失败');
  1612. }
  1613. util::complete();
  1614. }
  1615. //运费计算 ssh 2021.1.24
  1616. public function actionFreight()
  1617. {
  1618. //2021.3.28 接入达达
  1619. $get = Yii::$app->request->get();
  1620. $post = Yii::$app->request->post();
  1621. if (empty($get)) {
  1622. $get = $post;
  1623. }
  1624. $orderId = $get['id'] ?? 0; //订单ID
  1625. $customId = $get['customId'] ?? 0;
  1626. if (empty($orderId)) {
  1627. //自定义运费
  1628. //freight::getCost();
  1629. if (empty($customId)) {
  1630. util::fail("请选择客户");
  1631. }
  1632. $customInfo = CustomClass::getById($customId);
  1633. if (empty($customInfo)) {
  1634. util::fail('没有找到客户');
  1635. }
  1636. $shop = $this->shop;
  1637. //花材信息
  1638. $productJson = $get['product'] ?? '';
  1639. // $productJson = '[{"productId":31993,"bigNum":1,"smallNum":0}]';
  1640. if (empty($productJson)) {
  1641. util::fail('请选择花材');
  1642. }
  1643. $productList = json_decode($productJson, true);
  1644. if (empty($productList)) {
  1645. util::fail('请选择花材');
  1646. }
  1647. $productList = ProductClass::mergeItemInfo($productList);
  1648. $weight = 0;
  1649. $price = 0;
  1650. $productData = ProductClass::getProductMapData($productList);
  1651. $bigNum = 0;
  1652. foreach ($productList as $key => $val) {
  1653. $productId = $val['productId'];
  1654. $w = ProductClass::getWeight($val['productId'], $val['bigNum'], $val['smallNum']);
  1655. $bigNum += $val['bigNum'];
  1656. $weight = bcadd($w, $weight, 2);
  1657. $ratio = $productData[$productId]['ratio'] ?? 0;
  1658. //大小数量合并多少扎
  1659. $itemNum = ProductClass::mergeItemNum($val['bigNum'], $val['smallNum'], $ratio);
  1660. //售卖价格
  1661. $itemPrice = $productData[$productId]['price'] ?? 0;
  1662. //合计价格
  1663. $price = bcadd($price, bcmul($itemNum, $itemPrice, 2), 2);
  1664. }
  1665. //没有经纬度的客户运费直接返回空 ssh 20210612
  1666. if (empty($customInfo['lat']) || empty($customInfo['long'])) {
  1667. util::success(['sedCost' => '']);
  1668. }
  1669. $cost = freight::getCost($shop->lat, $shop->long, $customInfo['lat'], $customInfo['long'], $weight);
  1670. util::success(['sedCost' => $cost]);
  1671. }
  1672. $province = $get['province'] ?? '';
  1673. $city = $get['city'] ?? '';
  1674. $address = $get['address'] ?? '';
  1675. $floor = $get['floor'] ?? '';
  1676. $customName = $get['customName'] ?? '';
  1677. $customMobile = $get['customMobile'] ?? '';
  1678. $fullAddress = $province . $city . $address . $floor;
  1679. $sendTime = $get['sendTime'] ?? '';
  1680. $lat = $get['lat'] ?? '';
  1681. $lng = $get['long'] ?? '';
  1682. if (empty($lat) || empty($lng) || empty($fullAddress)) {
  1683. util::fail('请填写客户地址');
  1684. }
  1685. ini_set('date.timezone', 'Asia/Shanghai');
  1686. if (!empty($sendTime)) {
  1687. //配送时间不为空
  1688. // 预约发单时间(预约时间unix时间戳(10位),精确到分;整分钟为间隔,并且需要至少提前5分钟预约
  1689. $sendTimeInt = strtotime($sendTime);
  1690. $now = time();
  1691. $diff = $sendTimeInt - $now;
  1692. //因服务器写入时间,改为至少提前6分钟
  1693. if ($diff <= 360) {
  1694. util::fail('配送时间至少提前6分钟');
  1695. }
  1696. } else {
  1697. //默认立即发送
  1698. $sendTime = 0;
  1699. }
  1700. //更新订单表
  1701. $info = OrderService::getOrderInfo($orderId);
  1702. OrderClass::valid($info, $this->shopId);
  1703. if ($sendTime) {
  1704. $sendTime = date('Y-m-d H:i', strtotime($sendTime));
  1705. } else {
  1706. $sendTime = '0000-00-00 00:00:00';
  1707. }
  1708. $expressAddInfo = [
  1709. 'customName' => $customName,
  1710. 'customMobile' => $customMobile,
  1711. 'province' => $province,
  1712. 'city' => $city,
  1713. 'address' => $address,
  1714. 'floor' => $floor,
  1715. 'lat' => $lat,
  1716. 'long' => $lng,
  1717. 'sendTime' => $sendTime,
  1718. ];
  1719. OrderClass::updateCustomExpressInfo($orderId, $expressAddInfo);
  1720. //计算运费
  1721. $info['province'] = $province;
  1722. $info['city'] = $city;
  1723. $info['address'] = $address;
  1724. $info['floor'] = $floor;
  1725. $info['fullAddress'] = $fullAddress;
  1726. $info['lat'] = $lat;
  1727. $info['long'] = $lng;
  1728. $info['sendTime'] = $expressAddInfo['sendTime'];
  1729. $res = DadaExpressServices::queryDeliverFee($info);
  1730. util::success(['sedCost' => $res['fee']]);
  1731. }
  1732. //发快递和第三方配送 ssh 2021.1.24
  1733. public function actionThirdSend()
  1734. {
  1735. $get = Yii::$app->request->get();
  1736. $id = isset($get['id']) ? $get['id'] : 0;
  1737. $info = OrderService::getById($id, true);
  1738. OrderClass::valid($info->attributes, $this->shopId);
  1739. if (empty($info->lat) || empty($info->long) || empty($info->fullAddress)) {
  1740. util::fail('请填写客户地址');
  1741. }
  1742. $connection = Yii::$app->db;
  1743. $transaction = $connection->beginTransaction();
  1744. try {
  1745. $respond = OrderClass::thirdSend($info, $get);
  1746. $transaction->commit();
  1747. util::success($respond);
  1748. } catch (\Exception $exception) {
  1749. $transaction->rollBack();
  1750. Yii::info("发快递操作报错:" . $exception->getMessage());
  1751. util::fail('操作失败' . $exception->getMessage());
  1752. }
  1753. }
  1754. //确认送达 ssh 2021.1.24
  1755. public function actionReach()
  1756. {
  1757. $get = Yii::$app->request->get();
  1758. $id = isset($get['id']) ? $get['id'] : 0;
  1759. $info = OrderClass::getById($id, true);
  1760. OrderClass::valid($info->attributes, $this->shopId);
  1761. $connection = Yii::$app->db;
  1762. $transaction = $connection->beginTransaction();
  1763. try {
  1764. OrderService::reach($info);
  1765. $transaction->commit();
  1766. } catch (\Exception $exception) {
  1767. $transaction->rollBack();
  1768. Yii::info("送达操作报错:" . $exception->getMessage());
  1769. util::fail('操作失败');
  1770. }
  1771. util::complete();
  1772. }
  1773. //下单要用到的相关信息 ssh 2019.12.6
  1774. public function actionOrderRelate()
  1775. {
  1776. $regionTree = RegionService::tree();
  1777. $shop = $this->shop->attributes;
  1778. $freight = ['first' => 5, 'add' => 2];
  1779. $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
  1780. $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'txMapKey' => $mapKey, 'merchant' => $shop];
  1781. util::success($out);
  1782. }
  1783. //客户欠款的订单 ssh 2021.2.4
  1784. public function actionDebtList()
  1785. {
  1786. $get = Yii::$app->request->get();
  1787. $id = $get['id'] ?? 0;
  1788. $info = CustomClass::getCustom($id);
  1789. CustomClass::valid($info, $this->shopId);
  1790. $mainId = $this->mainId;
  1791. $where = ['mainId' => $mainId, 'customId' => $id, 'debt' => 1];
  1792. $searchTime = $get['searchTime'] ?? '';
  1793. if (!empty($searchTime)) {
  1794. $startTime = $get['startTime'] ?? '';
  1795. $endTime = $get['endTime'] ?? '';
  1796. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  1797. $where['payTime'] = ['between', [$period['startTime'], $period['endTime']]];
  1798. }
  1799. $list = OrderClass::getAllByCondition($where, 'addTime DESC', ['id', 'orderSn', 'actPrice', 'addTime', 'remainDebtPrice', 'payTime']);
  1800. $result = ['customInfo' => $info, 'list' => $list];
  1801. util::success($result);
  1802. }
  1803. //更新打印次数
  1804. public function actionAddPrintNum()
  1805. {
  1806. $id = Yii::$app->request->get('id', 0);
  1807. $order = OrderClass::getById($id, true);
  1808. OrderClass::valid($order, $this->shopId);
  1809. $order->printNum += 1;
  1810. $order->save();
  1811. util::complete();
  1812. }
  1813. //打印订单 ssh 20210714
  1814. public function actionCloudPrintOrder()
  1815. {
  1816. $get = Yii::$app->request->get();
  1817. $id = $get['id'] ?? 0;
  1818. $showPrice = $get['showPrice'] ?? 1;
  1819. $order = OrderClass::getById($id, true);
  1820. OrderClass::valid($order, $this->shopId);
  1821. if ($order->status == OrderClass::ORDER_STATUS_UN_PAY) {
  1822. util::fail('订单还没有付款');
  1823. }
  1824. if ($order->status == OrderClass::ORDER_STATUS_CANCEL) {
  1825. util::fail('订单已取消');
  1826. }
  1827. $ext = $this->shopExt;
  1828. if (isset($ext->printSn) == false || isset($ext->printKey) == false || empty($ext->printSn) || empty($ext->printKey)) {
  1829. util::success(['hasNoPrint' => 1]);
  1830. }
  1831. OrderClass::onlinePrint($order, $showPrice);
  1832. $order->printNum += 1;
  1833. $order->save();
  1834. util::complete();
  1835. }
  1836. //订单确认完成 ssh 20210809
  1837. public function actionConfirmFinish()
  1838. {
  1839. $payWay = Yii::$app->request->get('payWay', -1);
  1840. $id = Yii::$app->request->get('id', 0);
  1841. $clearType = Yii::$app->request->get('clearType', 0);
  1842. $connection = Yii::$app->db;
  1843. $transaction = $connection->beginTransaction();
  1844. try {
  1845. $order = OrderClass::getById($id, true);
  1846. OrderClass::valid($order, $this->shopId);
  1847. $purchaseId = $order->purchaseId ?? 0;
  1848. $purchase = PurchaseClass::getById($purchaseId, true);
  1849. if (empty($purchase)) {
  1850. util::fail('没有采购信息');
  1851. }
  1852. if ($clearType == 1) {
  1853. //欠款
  1854. $payWay = dict::getDict('payWay', 'debtPay');
  1855. } elseif ($clearType == 2) {
  1856. //已收款
  1857. if ($payWay == -1) {
  1858. util::fail('请选择收款方式');
  1859. }
  1860. $shopAdmin = $this->shopAdmin;
  1861. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  1862. util::fail('超管才能发起已收款');
  1863. }
  1864. } else {
  1865. util::fail('请选择结算方式');
  1866. }
  1867. //不需要打印
  1868. $order->needPrint = dict::getDict('needPrint', 'noNeed');
  1869. $order->save();
  1870. //支付
  1871. PurchaseService::payAfter($purchase, $payWay);
  1872. OrderService::payAfter($order, $payWay);
  1873. //自己送
  1874. $info = OrderClass::getById($id, true);
  1875. OrderClass::selfSend($info);
  1876. //确认送达,并且不需要微信通知
  1877. Yii::$app->params['noNeedWxNotice'] = 1;
  1878. $info = OrderClass::getById($id, true);
  1879. OrderService::reach($info);
  1880. $transaction->commit();
  1881. util::complete('操作成功');
  1882. } catch (\Exception $exception) {
  1883. $transaction->rollBack();
  1884. Yii::info("确认完成订单报错:" . $exception->getMessage());
  1885. util::fail('操作失败');
  1886. }
  1887. }
  1888. //取消订单 ssh 20220110
  1889. public function actionCancel()
  1890. {
  1891. $shopAdmin = $this->shopAdmin;
  1892. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  1893. util::fail('超管才能取消订单');
  1894. }
  1895. $id = Yii::$app->request->get('id');
  1896. $order = OrderClass::getById($id, true);
  1897. if ($order->orderType == 2) {
  1898. util::fail('客户下单,不能主动取消');
  1899. }
  1900. OrderClass::valid($order, $this->shopId);
  1901. OrderService::expire($order, true);
  1902. util::complete('已取消');
  1903. }
  1904. //获取收款语音播报地址 ssh 20211231
  1905. public function actionGetPayVoice()
  1906. {
  1907. $id = Yii::$app->request->get('id');
  1908. $order = OrderClass::getById($id, true);
  1909. $payWay = $order->payWay ?? 0;
  1910. $money = floatval($order->actPrice);
  1911. $payment = $payWay == dict::getDict('payWay', 'alipay') ? '支付宝' : '微信';
  1912. $msg = $payment . '收款' . $money . '元';
  1913. $audio = baiduAip::transfer($msg, 4, 0);
  1914. //上传到oss
  1915. $file = time() . rand(10000, 999999) . '.mp3';
  1916. $filePath = 'tmp/arrival/money/' . $file;
  1917. oss::uploadTmpAudio($filePath, $audio);
  1918. $url = Yii::$app->params['ghsImgHost'] . $filePath;
  1919. util::success(['url' => $url]);
  1920. }
  1921. //修改备注
  1922. public function actionModifyRemark()
  1923. {
  1924. $post = Yii::$app->request->post();
  1925. $id = $post['id'] ?? 0;
  1926. $remark = $post['remark'] ?? '';
  1927. $order = OrderClass::getById($id, true);
  1928. if (empty($order)) {
  1929. util::fail('没有找到订单');
  1930. }
  1931. if ($order->mainId != $this->mainId) {
  1932. util::fail('不是你的订单');
  1933. }
  1934. $cgId = $order->purchaseId ?? 0;
  1935. $cg = PurchaseClass::getById($cgId, true);
  1936. if (empty($cg)) {
  1937. util::fail('采购单没有找到');
  1938. }
  1939. $order->remark = $remark;
  1940. $order->save();
  1941. $cg->remark = $remark;
  1942. $cg->save();
  1943. util::complete('修改成功');
  1944. }
  1945. //修改订单的确认时间 ssh 20240511
  1946. public function actionModifyOrderConfirmTime()
  1947. {
  1948. $get = Yii::$app->request->get();
  1949. $id = $get['id'] ?? 0;
  1950. $date = $get['date'] ?? '';
  1951. if (empty($date)) {
  1952. util::fail('请选择日期');
  1953. }
  1954. $order = OrderClass::getById($id, true);
  1955. if (empty($order)) {
  1956. util::fail('没有找到订单');
  1957. }
  1958. if ($order->mainId != $this->mainId) {
  1959. util::fail('不是你的订单');
  1960. }
  1961. if ($order->payStatus == 0) {
  1962. util::fail('没有确认的订单');
  1963. }
  1964. $mainId = $this->mainId;
  1965. //超管或者约定的人可以修改日期
  1966. if (getenv('YII_ENV') == 'production') {
  1967. if (in_array($mainId, [23390])) {
  1968. if (!in_array($this->adminId, [24586, 23960])) {
  1969. util::fail('你不能修改哦');
  1970. }
  1971. }
  1972. } else {
  1973. if (in_array($mainId, [644])) {
  1974. if (!in_array($this->adminId, [919])) {
  1975. }
  1976. }
  1977. }
  1978. $payTime = $order->payTime;
  1979. $time = strtotime($payTime);
  1980. $after = date("H:i:s", $time);
  1981. $new = $date . ' ' . $after;
  1982. $cgId = $order->purchaseId ?? 0;
  1983. $cg = PurchaseClass::getById($cgId, true);
  1984. if (empty($cg)) {
  1985. util::fail('没有找到订单信息');
  1986. }
  1987. if (strtotime($new) > time()) {
  1988. util::fail('不能修改成未来时间');
  1989. }
  1990. $order->payTime = $new;
  1991. $order->save();
  1992. $cg->payTime = $new;
  1993. $cg->save();
  1994. util::complete('修改成功');
  1995. }
  1996. //应收款统计 ssh 20240528
  1997. public function actionAccountList()
  1998. {
  1999. $get = Yii::$app->request->get();
  2000. $mainId = $this->mainId;
  2001. $export = $get['export'] ?? 0;
  2002. $debt = isset($get['debt']) && is_numeric($get['debt']) ? $get['debt'] : -1;
  2003. $searchTime = isset($get['searchTime']) && !empty($get['searchTime']) ? $get['searchTime'] : 'today';
  2004. $startTime = $get['startTime'] ?? '';
  2005. $endTime = $get['endTime'] ?? '';
  2006. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  2007. $start = $period['startTime'];
  2008. $end = $period['endTime'];
  2009. $customList = CustomClass::getAllByCondition(['ownMainId' => $this->mainId], null, 'id,name', 'id');
  2010. $currentStartDate = date('Y-m-d', strtotime($start));
  2011. $currentEndDate = date('Y-m-d', strtotime($end));
  2012. $currentStartTime = $currentStartDate . ' 00:00:00';
  2013. $currentEndTime = $currentEndDate . ' 23:59:59';
  2014. $where = ['mainId' => $mainId];
  2015. if ($debt > -1) {
  2016. $where['debt'] = $debt;
  2017. }
  2018. $where['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
  2019. $orderList = OrderClass::getAllByCondition($where, null, '*');
  2020. $list = [];
  2021. $totalAmount = 0;
  2022. if (!empty($orderList)) {
  2023. foreach ($orderList as $orderInfo) {
  2024. $actPrice = $orderInfo['actPrice'] ?? 0;
  2025. $customId = $orderInfo['customId'] ?? 0;
  2026. $status = $orderInfo['status'] ?? 0;
  2027. $book = $orderInfo['book'] ?? 0;
  2028. if ($status == 1 || $status == 5) {
  2029. continue;
  2030. }
  2031. if ($book == 1 && $status == 2) {
  2032. continue;
  2033. }
  2034. if (isset($list[$customId])) {
  2035. $list[$customId]['amount'] = bcadd($list[$customId]['amount'], $actPrice, 2);
  2036. $list[$customId]['num'] = bcadd($list[$customId]['num'], 1);
  2037. } else {
  2038. $name = $customList[$customId] && $customList[$customId]['name'] ? $customList[$customId]['name'] : '未命名';
  2039. $list[$customId] = ['id' => $customId, 'name' => $name, 'amount' => $actPrice, 'num' => 1];
  2040. }
  2041. $totalAmount = bcadd($totalAmount, $actPrice, 2);
  2042. }
  2043. $list = array_values($list);
  2044. }
  2045. if ($export == 1) {
  2046. if (empty($list)) {
  2047. util::fail('没有数据需要导出');
  2048. }
  2049. ini_set('memory_limit', '2045M');
  2050. set_time_limit(0);
  2051. OrderClass::exportAccountList($list, $mainId);
  2052. util::stop();
  2053. }
  2054. util::success(['list' => $list, 'totalAmount' => $totalAmount]);
  2055. }
  2056. //应收款统计 ssh 20240528
  2057. public function actionPastList()
  2058. {
  2059. $get = Yii::$app->request->get();
  2060. $export = $get['export'] ?? 0;
  2061. $searchTime = isset($get['searchTime']) && !empty($get['searchTime']) ? $get['searchTime'] : 'today';
  2062. $startTime = $get['startTime'] ?? '';
  2063. $endTime = $get['endTime'] ?? '';
  2064. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  2065. $end = $period['endTime'];
  2066. $customList = CustomClass::getAllByCondition(['ownMainId' => $this->mainId], null, 'id,name,mobile', 'id');
  2067. $currentDate = date('Y-m-d 00:00:00', bcadd(strtotime($end), 86400));
  2068. $totalAmount = 0;
  2069. if (!empty($customList)) {
  2070. foreach ($customList as $key => $custom) {
  2071. $customId = $custom['id'] ?? 0;
  2072. $change = CustomDebtChangeClass::getByCondition(['customId' => $customId, 'addTime<' => $currentDate], true, 'addTime DESC');
  2073. $amount = $change->balance ?? 0;
  2074. $totalAmount = bcadd($totalAmount, $amount, 2);
  2075. $customList[$key]['currentDebAmount'] = $amount;
  2076. }
  2077. $customList = array_values($customList);
  2078. }
  2079. if ($export == 1) {
  2080. $mainId = $this->mainId;
  2081. if (empty($customList)) {
  2082. util::fail('没有数据需要导出');
  2083. }
  2084. ini_set('memory_limit', '2045M');
  2085. set_time_limit(0);
  2086. OrderClass::exportPastList($customList, $mainId);
  2087. util::stop();
  2088. }
  2089. util::success(['list' => $customList, 'totalAmount' => $totalAmount]);
  2090. }
  2091. //客户业绩,有多个地方,需要同步,搜索关键词 customYj ssh 20240628
  2092. public function actionYj()
  2093. {
  2094. $get = Yii::$app->request->get();
  2095. $mainId = $this->mainId;
  2096. $export = $get['export'] ?? 0;
  2097. $debt = isset($get['debt']) && is_numeric($get['debt']) ? $get['debt'] : -1;
  2098. $searchTime = isset($get['searchTime']) && !empty($get['searchTime']) ? $get['searchTime'] : 'today';
  2099. $startTime = $get['startTime'] ?? '';
  2100. $endTime = $get['endTime'] ?? '';
  2101. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  2102. $start = $period['startTime'];
  2103. $end = $period['endTime'];
  2104. $customList = CustomClass::getAllByCondition(['ownMainId' => $mainId], null, '*', 'id');
  2105. $currentStartDate = date('Y-m-d', strtotime($start));
  2106. $currentEndDate = date('Y-m-d', strtotime($end));
  2107. $currentStartTime = $currentStartDate . ' 00:00:00';
  2108. $currentEndTime = $currentEndDate . ' 23:59:59';
  2109. $where = ['mainId' => $mainId];
  2110. if ($debt > -1) {
  2111. $where['debt'] = $debt;
  2112. }
  2113. $where['payTime'] = ['between', [$currentStartTime, $currentEndTime]];
  2114. $orderList = OrderClass::getAllByCondition($where, null, '*');
  2115. $list = [];
  2116. $totalActPrice = 0;
  2117. $totalOrderPrice = 0;
  2118. $totalCarton = 0;
  2119. $totalPack = 0;
  2120. $totalFreight = 0;
  2121. $totalTkPrice = 0;
  2122. //增加项
  2123. $totalOnlyTkPrice = 0;
  2124. $totalNum = 0;
  2125. if (!empty($orderList)) {
  2126. foreach ($orderList as $orderInfo) {
  2127. $actPrice = $orderInfo['actPrice'] ?? 0;
  2128. $orderPrice = $orderInfo['orderPrice'] ?? 0;
  2129. $customId = $orderInfo['customId'] ?? 0;
  2130. $status = $orderInfo['status'] ?? 0;
  2131. $book = $orderInfo['book'] ?? 0;
  2132. $orderSn = $orderInfo['orderSn'] ?? '';
  2133. $tkPrice = $orderInfo['tkPrice'] ?? 0;
  2134. if ($status == 1 || $status == 5) {
  2135. continue;
  2136. }
  2137. if ($book == 1 && $status == 2) {
  2138. continue;
  2139. }
  2140. $carton = 0;
  2141. $pack = 0;
  2142. $freight = 0;
  2143. $orderItemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
  2144. if ($actPrice > 0) {
  2145. if (!empty($orderItemList)) {
  2146. foreach ($orderItemList as $orderItem) {
  2147. $num = $orderItem['xhNum'] ?? 0;
  2148. $unitPrice = $orderItem['xhUnitPrice'] ?? 0;
  2149. $refundNum = $orderItem['refundNum'] ?? 0;
  2150. $classId = $orderItem['classId'] ?? 0;
  2151. if (getenv('YII_ENV') == 'production') {
  2152. //小向算打包纸箱费用
  2153. if ($mainId == 23390) {
  2154. $remainNum = bcsub($num, $refundNum);
  2155. $amount = bcmul($remainNum, $unitPrice, 2);
  2156. if ($classId == 72106) {
  2157. $carton = bcadd($carton, $amount, 2);
  2158. }
  2159. if ($classId == 72108) {
  2160. $pack = bcadd($pack, $amount, 2);
  2161. }
  2162. if ($classId == 73118) {
  2163. $freight = bcadd($freight, $amount, 2);
  2164. }
  2165. }
  2166. }
  2167. }
  2168. }
  2169. }
  2170. //增加项
  2171. if ($tkPrice > 0) {
  2172. $refundList = RefundOrderClass::getAllByCondition(['relateOrderSn' => $orderSn], null, '*', null, true);
  2173. if (!empty($refundList)) {
  2174. foreach ($refundList as $refundInfo) {
  2175. if ($refundInfo->status == 1) {
  2176. if ($refundInfo->refundType == 2) {
  2177. $refundPrice = $refundInfo->refundPrice ?? 0;
  2178. $totalOnlyTkPrice = bcadd($totalOnlyTkPrice, $refundPrice, 2);
  2179. }
  2180. }
  2181. }
  2182. }
  2183. }
  2184. $totalCarton = bcadd($totalCarton, $carton, 2);
  2185. $totalPack = bcadd($totalPack, $pack, 2);
  2186. $totalFreight = bcadd($totalFreight, $freight, 2);
  2187. $totalTkPrice = bcadd($totalTkPrice, $tkPrice, 2);
  2188. $totalActPrice = bcadd($totalActPrice, $actPrice, 2);
  2189. $totalOrderPrice = bcadd($totalOrderPrice, $orderPrice, 2);
  2190. $totalNum++;
  2191. if (isset($list[$customId])) {
  2192. $list[$customId]['actPrice'] = bcadd($list[$customId]['actPrice'], $actPrice, 2);
  2193. $list[$customId]['orderPrice'] = bcadd($list[$customId]['orderPrice'], $orderPrice, 2);
  2194. $list[$customId]['num'] = bcadd($list[$customId]['num'], 1);
  2195. $list[$customId]['carton'] = bcadd($list[$customId]['carton'], $carton, 2);
  2196. $list[$customId]['pack'] = bcadd($list[$customId]['pack'], $pack, 2);
  2197. $list[$customId]['freight'] = bcadd($list[$customId]['freight'], $freight, 2);
  2198. $list[$customId]['tkPrice'] = bcadd($list[$customId]['tkPrice'], $tkPrice, 2);
  2199. } else {
  2200. $name = $customList[$customId] && $customList[$customId]['name'] ? $customList[$customId]['name'] : '未命名';
  2201. $mobile = $customList[$customId] && $customList[$customId]['mobile'] ? $customList[$customId]['mobile'] : '0';
  2202. $list[$customId] = [
  2203. 'id' => $customId,
  2204. 'name' => $name,
  2205. 'mobile' => $mobile,
  2206. 'orderPrice' => $orderPrice,
  2207. 'actPrice' => $actPrice,
  2208. 'num' => 1,
  2209. 'carton' => $carton,
  2210. 'pack' => $pack,
  2211. 'freight' => $freight,
  2212. 'tkPrice' => $tkPrice,
  2213. ];
  2214. }
  2215. }
  2216. foreach ($customList as $key => $custom) {
  2217. $customId = $custom['id'] ?? 0;
  2218. if (isset($list[$customId]) == false) {
  2219. $list[$customId] = [
  2220. 'id' => $customId,
  2221. 'name' => $custom['name'],
  2222. 'mobile' => $custom['mobile'],
  2223. 'actPrice' => 0,
  2224. 'num' => 0,
  2225. 'carton' => 0,
  2226. 'pack' => 0,
  2227. 'freight' => 0,
  2228. 'tkPrice' => 0,
  2229. 'orderPrice' => 0,
  2230. ];
  2231. }
  2232. }
  2233. $list = array_values($list);
  2234. }
  2235. if ($export == 1) {
  2236. if (empty($list)) {
  2237. util::fail('没有数据需要导出');
  2238. }
  2239. ini_set('memory_limit', '2045M');
  2240. set_time_limit(0);
  2241. OrderClass::exportYj($list, $mainId);
  2242. util::stop();
  2243. }
  2244. util::success([
  2245. 'list' => $list,
  2246. 'totalActPrice' => $totalActPrice,
  2247. 'totalOrderPrice' => $totalOrderPrice,
  2248. 'totalCarton' => $totalCarton,
  2249. 'totalNum' => $totalNum,
  2250. 'totalPack' => $totalPack,
  2251. 'totalFreight' => $totalFreight,
  2252. 'totalTkPrice' => $totalTkPrice,
  2253. //增加项
  2254. 'totalOnlyTkPrice' => $totalOnlyTkPrice,
  2255. ]);
  2256. }
  2257. //修改配送人 ssh 20240824
  2258. public function actionChangeSendStaff()
  2259. {
  2260. $staff = $this->shopAdmin;
  2261. if (isset($staff->finance) == false || $staff->finance == 0) {
  2262. util::fail('请有财务权限的人修改');
  2263. }
  2264. $get = Yii::$app->request->get();
  2265. $staffId = $get['staffId'] ?? 0;
  2266. $orderId = $get['orderId'] ?? 0;
  2267. $order = OrderClass::getById($orderId, true);
  2268. if (empty($order)) {
  2269. util::fail('没有找到订单');
  2270. }
  2271. if ($order->mainId != $this->mainId) {
  2272. util::fail('不是你的');
  2273. }
  2274. $staff = ShopAdminClass::getById($staffId, true);
  2275. if (empty($staff)) {
  2276. util::fail('没有找到员工');
  2277. }
  2278. if ($staff->mainId != $this->mainId) {
  2279. util::fail('不是你的员工');
  2280. }
  2281. $staffName = $staff->name ?? '';
  2282. $order->sendStaffId = $staffId;
  2283. $order->sendStaffName = $staffName;
  2284. $order->save();
  2285. util::complete('修改成功');
  2286. }
  2287. }