OrderController.php 99 KB

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