OrderController.php 69 KB

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