OrderController.php 103 KB

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