OrderController.php 69 KB

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