OrderController.php 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108
  1. <?php
  2. namespace hd\controllers;
  3. use biz\shop\classes\ShopExtClass;
  4. use biz\sj\services\MerchantExtendService;
  5. use biz\sj\services\MerchantService;
  6. use bizHd\custom\classes\CustomClass;
  7. use bizHd\custom\classes\HdClass;
  8. use bizHd\goods\classes\GoodsClass;
  9. use bizHd\merchant\services\ShopService;
  10. use bizHd\order\classes\OrderClass;
  11. use bizHd\order\classes\OrderItemClass;
  12. use bizHd\order\classes\OrderSendClass;
  13. use bizHd\order\services\OrderService;
  14. use bizHd\product\classes\ProductClass;
  15. use bizHd\purchase\classes\PurchaseClass;
  16. use bizHd\saas\services\RegionService;
  17. use bizHd\shop\classes\ShopClass;
  18. use bizHd\user\services\UserService;
  19. use bizHd\work\classes\WorkClass;
  20. use bizHd\wx\classes\WxOpenClass;
  21. use common\components\dict;
  22. use common\components\dateUtil;
  23. use common\components\noticeUtil;
  24. use common\components\orderSn;
  25. use common\components\payUtil;
  26. use common\services\xhPayToolService;
  27. use Yii;
  28. use common\components\util;
  29. use common\components\stringUtil;
  30. use bizHd\promote\services\CouponService;
  31. use common\components\httpUtil;
  32. use biz\wx\classes\WxMessageClass;
  33. use common\components\lakala\Lakala;
  34. class OrderController extends BaseController
  35. {
  36. public $guestAccess = ['order-relate', 'fast-pay', 'create-order', 'list'];
  37. public function actionDebt()
  38. {
  39. $get = Yii::$app->request->get();
  40. $id = $get['id'] ?? 0;
  41. $info = OrderClass::getById($id, true);
  42. if (empty($info)) {
  43. util::fail('没有找到订单');
  44. }
  45. if ($info->mainId != $this->mainId) {
  46. util::fail('不是你的订单');
  47. }
  48. //4秒内不允许重复提交
  49. $cacheKey = 'ls_set_order_debt_' . $id;
  50. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  51. if (!empty($has)) {
  52. util::fail('请稍等');
  53. }
  54. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 4, 'has']);
  55. if ($info->status != 1) {
  56. util::fail('订单已付款或取消');
  57. }
  58. $payWay = dict::getDict('payWay', 'debtPay');
  59. $connection = Yii::$app->db;
  60. $transaction = $connection->beginTransaction();
  61. try {
  62. OrderClass::payAfter($info, $payWay);
  63. $transaction->commit();
  64. util::complete('已赊账');
  65. } catch (\Exception $exception) {
  66. $transaction->rollBack();
  67. Yii::info("赊账失败原因:" . $exception->getMessage());
  68. util::fail('操作失败');
  69. }
  70. }
  71. //取消订单 ssh 20221231
  72. public function actionCancel()
  73. {
  74. //避免重复提交
  75. $adminId = $this->adminId;
  76. util::checkRepeatCommit($adminId, 8);
  77. $get = Yii::$app->request->get();
  78. $id = $get['id'] ?? 0;
  79. $order = OrderClass::getById($id, true);
  80. OrderClass::valid($order, $this->mainId);
  81. $deadTime = $order->deadline ?? 0;
  82. $current = time();
  83. $diff = bcsub($deadTime, $current);
  84. if ($diff < 60) {
  85. util::fail('60秒后将自动取消');
  86. }
  87. $connection = Yii::$app->db;
  88. $transaction = $connection->beginTransaction();
  89. try {
  90. OrderClass::setExpire($order, true);
  91. $transaction->commit();
  92. util::complete();
  93. } catch (\Exception $exception) {
  94. $transaction->rollBack();
  95. Yii::info("取消原因:" . $exception->getMessage());
  96. util::fail('取消失败');
  97. }
  98. }
  99. //修改订单 ssh 20220926
  100. public function actionUpdate()
  101. {
  102. $post = Yii::$app->request->post();
  103. $id = $post['id'] ?? 0;
  104. $order = OrderClass::getById($id, true);
  105. OrderClass::valid($order, $this->mainId);
  106. unset($post['id']);
  107. if ($order->status == 3) {
  108. util::fail('订单已配送');
  109. }
  110. if ($order->status == 4) {
  111. util::fail('订单已完成');
  112. }
  113. if ($order->status == 5) {
  114. util::fail('订单已取消');
  115. }
  116. if ($order->fromType == 4) {
  117. util::fail('请在美团APP上修改');
  118. }
  119. $address = $post['address'] ?? '';
  120. $floor = $post['floor'] ?? '';
  121. $post['fullAddress'] = $address . $floor;
  122. OrderClass::updateById($id, $post);
  123. $workList = WorkClass::getAllByCondition(['orderId' => $id], null, '*', null, true);
  124. $remark = $post['remark'] ?? '';
  125. $reachDate = $post['reachDate'] ?? '';
  126. $reachPeriod = $post['reachPeriod'] ?? '';
  127. $cardInfo = $post['cardInfo'] ?? '';
  128. $anonymity = $post['anonymity'] ?? 0;
  129. $bookName = $post['bookName'] ?? '';
  130. if (!empty($workList)) {
  131. foreach ($workList as $work) {
  132. $work->remark = $remark;
  133. $work->reachDate = $reachDate;
  134. $work->reachPeriod = $reachPeriod;
  135. $work->cardInfo = $cardInfo;
  136. $work->anonymity = $anonymity;
  137. $work->bookName = $bookName;
  138. $work->save();
  139. }
  140. }
  141. $shopExt = ShopExtClass::getByCondition(['shopId' => $this->shopId], true);
  142. ShopExtClass::orderUpdateRemind($shopExt, $order);
  143. util::complete();
  144. }
  145. //客户欠款的订单 ssh 2021.2.4
  146. public function actionDebtList()
  147. {
  148. $get = Yii::$app->request->get();
  149. $id = $get['id'] ?? 0;
  150. $info = CustomClass::getById($id, true);
  151. CustomClass::valid($info, $this->shopId);
  152. $where = ['customId' => $id, 'debt' => 1];
  153. $searchTime = $get['searchTime'] ?? '';
  154. if (!empty($searchTime)) {
  155. $startTime = $get['startTime'] ?? '';
  156. $endTime = $get['endTime'] ?? '';
  157. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  158. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  159. }
  160. $list = OrderClass::getAllByCondition($where, 'addTime DESC', ['id', 'orderSn', 'actPrice', 'addTime', 'remainDebtPrice']);
  161. $result = ['customInfo' => $info, 'list' => $list];
  162. util::success($result);
  163. }
  164. //发货
  165. public function actionSend()
  166. {
  167. $get = Yii::$app->request->get();
  168. $id = isset($get['id']) ? $get['id'] : 0;
  169. $order = OrderClass::getById($id, true);
  170. if (empty($order)) {
  171. util::fail('没有找到订单');
  172. }
  173. OrderClass::valid($order, $this->mainId);
  174. if ($order->status != 2) {
  175. util::fail('订单不是待发货状态');
  176. }
  177. $workList = WorkClass::getAllByCondition(['orderId' => $id], null, '*', null, true);
  178. if (!empty($workList)) {
  179. $unComplete = false;
  180. foreach ($workList as $work) {
  181. if ($work->status != 1) {
  182. $unComplete = true;
  183. }
  184. }
  185. if ($unComplete == true) {
  186. util::fail('还有制作单没有完成');
  187. }
  188. }
  189. $order->status = 4;
  190. $order->save();
  191. util::complete('操作成功');
  192. }
  193. //打印订单 ssh 20220601
  194. public function actionPrintOrder()
  195. {
  196. $get = Yii::$app->request->get();
  197. $id = isset($get['id']) ? $get['id'] : 0;
  198. $order = OrderClass::getById($id, true);
  199. if (empty($order)) {
  200. util::fail('没有找到订单');
  201. }
  202. OrderClass::valid($order, $this->mainId);
  203. OrderClass::onlinePrint($order, true);
  204. util::complete();
  205. }
  206. //微信和支付宝付款码支付复查 ssh 20220422
  207. public function actionCodePayCheck()
  208. {
  209. ini_set('date.timezone', 'Asia/Shanghai');
  210. header("Content-type: text/html; charset=utf-8");
  211. $get = Yii::$app->request->get();
  212. $id = isset($get['id']) ? $get['id'] : 0;
  213. $order = OrderClass::getById($id, true);
  214. OrderClass::valid($order, $this->mainId);
  215. $orderSn = $order->orderSn ?? '';
  216. $totalFee = $order->mainPay ?? 0;
  217. if ($order->status == OrderClass::ORDER_STATUS_COMPLETE) {
  218. util::success(['returnStatus' => 'SUCCESS']);
  219. }
  220. if ($order->status != OrderClass::ORDER_STATUS_UN_PAY) {
  221. util::complete('订单不是待付款状态');
  222. }
  223. $connection = Yii::$app->db;
  224. $transaction = $connection->beginTransaction();
  225. try {
  226. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  227. $shop = $this->shop;
  228. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  229. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  230. $params = [
  231. 'appid' => 'OP00002119',
  232. 'serial_no' => '018b08cfddbd',
  233. 'merchant_no' => $shop->lklSjNo,
  234. 'term_no' => $shop->lklScanTermNo,
  235. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  236. 'lklCertificatePath' => $lklCertificatePath,
  237. ];
  238. $laResource = new Lakala($params);
  239. $scanParams = ['orderSn' => $orderSn,];
  240. $response = $laResource->query($scanParams);
  241. if (isset($response['code']) && $response['code'] == 'BBS00000') {
  242. if (isset($response['resp_data']['trade_state']) && $response['resp_data']['trade_state'] == 'SUCCESS') {
  243. $payWayType = dict::getDict('payWay', 'wxPay');
  244. $account_type = $response['resp_data']['account_type'] ?? '';
  245. if ($account_type == 'WECHAT') {
  246. $payWayType = dict::getDict('payWay', 'wxPay');
  247. }
  248. if ($account_type == 'ALIPAY') {
  249. $payWayType = dict::getDict('payWay', 'alipay');
  250. }
  251. $transactionId = $response['resp_data']['trade_no'] ?? '';
  252. $order->onlinePay = dict::getDict('onlinePay', 'yes');
  253. $order->save();
  254. $attach = '';
  255. payUtil::thirdPay($payWayType, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  256. $transaction->commit();
  257. //打印小票和语音播报
  258. $newOrder = OrderClass::getById($id, true);
  259. OrderClass::onlinePrint($newOrder);
  260. ShopExtClass::hdGatheringReport($newOrder);
  261. $shopId = $newOrder->shopId ?? 0;
  262. $shop = ShopClass::getById($shopId, true);
  263. WxMessageClass::gatheringIncomeInform($shop, $newOrder);
  264. util::success(['returnStatus' => 'SUCCESS']);
  265. } else {
  266. util::complete('未知状态..');
  267. }
  268. }
  269. util::complete('未知状态..');
  270. } catch (\Exception $e) {
  271. $transaction->rollBack();
  272. util::complete('支付失败');
  273. }
  274. }
  275. //微信和支付宝付款码支付 ssh 2021.4.11
  276. public function actionCodePay()
  277. {
  278. ini_set('date.timezone', 'Asia/Shanghai');
  279. header("Content-type: text/html; charset=utf-8");
  280. $get = Yii::$app->request->get();
  281. $id = isset($get['id']) ? $get['id'] : 0;
  282. $version = $get['version'] ?? 0;
  283. $order = OrderClass::getById($id, true);
  284. OrderClass::valid($order, $this->mainId);
  285. $shop = $this->shop;
  286. $sj = $shop->merchantName;
  287. $shopName = $shop->shopName;
  288. $name = $shopName == '首店' ? $sj : $sj . '-' . $shopName;
  289. $authCode = (string)$get['authCode'] ?? '';
  290. if ($version > 0) {
  291. if (empty($authCode)) {
  292. $msg = '没有扫到付款码';
  293. $remind = $msg . "(零售端付款码:{$authCode})" . '(' . $name . ')';
  294. noticeUtil::push($remind . ' 编号005', '15280215347');
  295. util::success(['returnStatus' => 'FAILURE'], $msg);
  296. }
  297. //微信文档说明 https://pay.weixin.qq.com/doc/v2/merchant/4011936234
  298. $wxPattern = '/^(10|11|12|13|14|15)\d{16}$/';
  299. //支付宝文档说明 https://opendocs.alipay.com/open/194/106039/
  300. $aliPattern = '/^(25|26|27|28|29|30)\d{14,22}$/';
  301. if (!preg_match($wxPattern, $authCode) && !preg_match($aliPattern, $authCode)) {
  302. $msg = '付款码错误,请使用微信或支付宝付款码';
  303. $remind = $msg . "(零售端付款码:{$authCode})" . '(' . $name . ')';
  304. //noticeUtil::push($remind . ' 编号009', '15280215347');
  305. util::success(['returnStatus' => 'FAILURE'], $msg);
  306. }
  307. } else {
  308. if (empty($authCode)) {
  309. util::fail('没有获取到支付码');
  310. }
  311. }
  312. $orderSn = $order->orderSn ?? '';
  313. $lsCodePayErrorKey = 'ls_code_pay_error_' . $id;
  314. $hasFailPay = Yii::$app->redis->executeCommand('GET', [$lsCodePayErrorKey]);
  315. //前面有付失败过,要重新生成单号
  316. if (!empty($hasFailPay)) {
  317. $oldOrderSn = $order->orderSn;
  318. $orderSn = orderSn::getOrderSn();
  319. $order->orderSn = $orderSn;
  320. $order->save();
  321. OrderItemClass::updateByCondition(['orderSn' => $oldOrderSn], ['orderSn' => $orderSn]);
  322. }
  323. $subject = '购买花材 ' . $orderSn;
  324. $totalFee = $order->mainPay ?? 0;
  325. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  326. $connection = Yii::$app->db;
  327. $transaction = $connection->beginTransaction();
  328. try {
  329. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  330. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  331. $params = [
  332. 'appid' => 'OP00002119',
  333. 'serial_no' => '018b08cfddbd',
  334. 'merchant_no' => $shop->lklSjNo,
  335. 'term_no' => $shop->lklScanTermNo,
  336. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  337. 'lklCertificatePath' => $lklCertificatePath,
  338. ];
  339. $laResource = new Lakala($params);
  340. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
  341. $scanParams = [
  342. 'orderSn' => $orderSn,
  343. 'amount' => $totalFee,
  344. 'capitalType' => $capitalType,
  345. 'notifyUrl' => $notifyUrl,
  346. 'subject' => $subject,
  347. 'authCode' => $authCode,
  348. ];
  349. $response = $laResource->scanPay($scanParams);
  350. if (isset($response['code']) && $response['code'] == 'BBS00000') {
  351. $account_type = $response['resp_data']['account_type'] ?? '';
  352. $payWayType = dict::getDict('payWay', 'wxPay');
  353. if ($account_type == 'WECHAT') {
  354. $payWayType = dict::getDict('payWay', 'wxPay');
  355. }
  356. if ($account_type == 'ALIPAY') {
  357. $payWayType = dict::getDict('payWay', 'alipay');
  358. }
  359. $order->payWay = $payWayType;
  360. $transactionId = $response['resp_data']['trade_no'] ?? '';
  361. $order->onlinePay = dict::getDict('onlinePay', 'yes');
  362. $order->save();
  363. $attach = '';
  364. payUtil::thirdPay($payWayType, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  365. $transaction->commit();
  366. //解决重复通知
  367. $cacheKey = 'hd_shop_order_pay_' . $orderSn;
  368. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  369. if (empty($has)) {
  370. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 300, 'has']);
  371. $newOrder = OrderClass::getById($id, true);
  372. //打印小票
  373. OrderClass::onlinePrint($newOrder);
  374. //语音播报
  375. ShopExtClass::hdGatheringReport($newOrder);
  376. $shopId = $newOrder->shopId ?? 0;
  377. $shop = ShopClass::getById($shopId, true);
  378. WxMessageClass::gatheringIncomeInform($shop, $newOrder);
  379. }
  380. util::success(['returnStatus' => 'SUCCESS']);
  381. } else {
  382. //标记有没付成功的次数,原因有可能是余额不足等
  383. Yii::$app->redis->executeCommand('SETEX', [$lsCodePayErrorKey, 1200, 'hasFail']);
  384. $msg = $response['msg'] ?? '';
  385. $retCode = $response['code'] ?? '';
  386. $fullMsg = $msg . "(零售端付款码:{$authCode})" . '(' . $name . ')';
  387. if ($retCode == 'BBS10000' || $retCode == 'BBS11105') {
  388. $shopId = $order->shopId;
  389. ShopExtClass::remindInputPassword($shopId);
  390. }
  391. //noticeUtil::push($fullMsg . ' ' . $retCode . ' 编号008', '15280215347');
  392. util::success(['returnStatus' => 'FAILURE', 'returnCode' => $retCode], $msg);
  393. }
  394. } catch (\Exception $e) {
  395. $transaction->rollBack();
  396. util::fail('支付失败');
  397. }
  398. }
  399. //开单操作 ssh 20220316
  400. public function actionCreateOrder()
  401. {
  402. $post = Yii::$app->request->post();
  403. $post['sjId'] = $this->sjId;
  404. $post['shopId'] = $this->shopId;
  405. $post['mainId'] = $this->mainId ?? 0;
  406. $now = time();
  407. $orderValidTime = getenv('ORDER_VALID_TIME') == false ? 600 : getenv('ORDER_VALID_TIME');
  408. $expireTime = $now + $orderValidTime;
  409. $post['deadline'] = $expireTime;
  410. $post['staffId'] = $this->shopAdminId ?? 0;
  411. $post['staffName'] = $this->shopAdmin->name ?? '';
  412. $post['flowerNum'] = isset($post['flowerNum']) && $post['flowerNum'] > 0 ? $post['flowerNum'] : 0;
  413. //默认情况开单员工和收款员工是同个人
  414. $staffId = $this->shopAdminId ?? 0;
  415. $staffName = $this->shopAdmin->name ?? '';
  416. if (empty($post['shopAdminId'])) {
  417. $post['shopAdminId'] = $staffId;
  418. $post['shopAdminName'] = $staffName;
  419. }
  420. if (empty($post['getStaffId'])) {
  421. $post['getStaffId'] = $staffId;
  422. $post['getStaffName'] = $this->shopAdmin->name ?? '';
  423. }
  424. $groupId = !empty($post['groupId']) ? $post['groupId'] : 0;
  425. $post['fromType'] = $post['fromType'] ?? 1;
  426. if ($post['fromType'] == dict::getDict('fromType', 'friend')) {
  427. if (empty($post['bookName'])) {
  428. util::fail('请填写订花人姓名');
  429. }
  430. }
  431. $customId = $post['customId'] ?? 0;
  432. $custom = CustomClass::getById($customId, true);
  433. if (empty($custom)) {
  434. util::fail('没有找到客户哦');
  435. }
  436. $hdId = $custom->hdId ?? 0;
  437. $hd = HdClass::getById($hdId, true);
  438. if (empty($hd)) {
  439. util::fail('客户对应的花店信息缺失,编号869');
  440. }
  441. $hdName = $hd->name ?? '';
  442. $post['hdId'] = $hdId;
  443. $post['hdName'] = $hdName;
  444. $post['customId'] = $customId;
  445. $customName = $custom->name ?? '';
  446. $post['customName'] = $customName;
  447. $post['customNamePy'] = stringUtil::py($customName);
  448. if (!empty($post['receiveMobile'])) {
  449. if (!stringUtil::isMobile($post['receiveMobile'])) {
  450. util::fail('请填写正确的收花人手机号');
  451. }
  452. }
  453. if (!empty($post['bookMobile'])) {
  454. if (!stringUtil::isMobile($post['bookMobile'])) {
  455. util::fail('请填写正确的订花人手机号');
  456. }
  457. }
  458. $hasPay = $post['hasPay'] ?? dict::getDict('hasPay', 'unPay');
  459. if (isset($post['isCashier']) && $post['isCashier'] == 1) {
  460. //收银台开单默认到店自取
  461. $post['sendType'] = dict::getDict('sendType', 'shopGet');
  462. }
  463. $productJson = $post['product'] ?? '';
  464. $productList = [];
  465. if (!empty($productJson)) {
  466. $productList = json_decode($productJson, true);
  467. }
  468. if (empty($productList) && empty($groupId)) {
  469. //商家手机上开单并生成制作单
  470. if (!empty($post['unitGoodsPrice'])) {
  471. $unitGoodsPrice = $post['unitGoodsPrice'];
  472. if (!is_numeric($unitGoodsPrice)) {
  473. util::fail('请输入正确的单价');
  474. }
  475. $productList = GoodsClass::orderCreateGoods($post);
  476. }
  477. }
  478. if (empty($productList) && empty($groupId)) {
  479. if ($post['lsGoodsPrice'] <= 0) {
  480. $lsGoodsPrice = $post['lsGoodsPrice'];
  481. if (!is_numeric($lsGoodsPrice)) {
  482. util::fail('请输入正确的金额');
  483. }
  484. util::fail('请填写金额或选商品');
  485. }
  486. }
  487. $connection = Yii::$app->db;
  488. $transaction = $connection->beginTransaction();
  489. try {
  490. $post['product'] = $productList;
  491. //阿东开5支老是会出现5扎情况跟踪
  492. ProductClass::adStockCheck($this->shop, $productList);
  493. //3秒内不允许重复开单
  494. $staffId = $this->shopAdminId ?? 0;
  495. $cacheKey = 'hd_create_order_' . $staffId . '_' . $customId;
  496. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  497. if (!empty($has)) {
  498. util::fail('稍等5秒再开单');
  499. }
  500. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 3, 'has']);
  501. $return = OrderService::createFinishOrder($post, $custom, $hasPay);
  502. $transaction->commit();
  503. //打印小票和语音播报
  504. $id = $return->id ?? 0;
  505. $order = OrderClass::getById($id, true);
  506. if ($order->fromType == 3 || $order->fromType == 4) {
  507. //除了客服号下单和美团下单,其它情况允许打小票
  508. } else {
  509. //前台打小票
  510. OrderClass::onlinePrint($order);
  511. }
  512. //前台提示收款多少钱
  513. ShopExtClass::hdGatheringReport($order);
  514. //前台提醒出示付款码
  515. if (isset($order->status) && $order->status == 1) {
  516. if (isset($post['isCashier']) && $post['isCashier'] == 1) {
  517. ShopExtClass::pleasePayReport($order);
  518. }
  519. }
  520. $shopId = $order->shopId ?? 0;
  521. $shop = ShopClass::getById($shopId, true);
  522. WxMessageClass::gatheringIncomeInform($shop, $order);
  523. //新制作单提示
  524. $shopExt = ShopExtClass::getByCondition(['shopId' => $this->shopId], true);
  525. ShopExtClass::newWorkRemind($shopExt, $order);
  526. util::success($return);
  527. } catch (\Exception $e) {
  528. $transaction->rollBack();
  529. Yii::error("失败原因:" . $e->getMessage());
  530. util::fail('下单失败');
  531. }
  532. }
  533. //下单要用到的相关信息 ssh 2019.12.6
  534. public function actionOrderRelate()
  535. {
  536. $regionTree = RegionService::tree();
  537. $shop = $this->shop->attributes;
  538. $freight = MerchantExtendService::getFreight($this->sjExtend);
  539. $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
  540. $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'thirdMapKey' => $mapKey, 'merchant' => $shop];
  541. util::success($out);
  542. }
  543. //余额支付 ssh 2019.12.6
  544. public function actionBalancePay()
  545. {
  546. $post = Yii::$app->request->post();
  547. $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
  548. $payPassword = isset($post['payPassword']) ? $post['payPassword'] : 0;
  549. $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
  550. $order = OrderService::getByOrderSn($orderSn);
  551. $userId = $this->adminId;
  552. $user = UserService::getUserInfo($userId);
  553. //验证支付密码是否正确
  554. UserService::validPayPassword($payPassword, $user);
  555. //支付前验证订单有效性
  556. OrderService::checkBeforePay($order);
  557. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  558. $totalFee = $order['prePrice'];
  559. $sourceType = 0;
  560. $discountData = OrderService::getDiscountPrice(['price' => $totalFee, 'sourceType' => $sourceType, 'couponId' => $couponId, 'userId' => $this->adminId]);
  561. $actPrice = $discountData['price'];
  562. $callbackParams = [];
  563. $respond = xhPayToolService::balancePay($callbackParams, $orderSn, $actPrice, $capitalType, $couponId);
  564. $balance = isset($respond['balance']) ? $respond['balance'] : 0;
  565. util::success(['discountAmount' => $discountData['discountAmount'], 'discountType' => $discountData['discountType'], 'balance' => $balance]);
  566. }
  567. //获取商城下单要用的微信支付和小程序支付参数 ssh 2019.21.3
  568. public function actionWxPay()
  569. {
  570. ini_set('date.timezone', 'Asia/Shanghai');
  571. $post = Yii::$app->request->post();
  572. $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
  573. $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
  574. $order = OrderService::getByOrderSn($orderSn);
  575. $orderId = $order['id'];
  576. //验证优惠券是否还有效
  577. if (!empty($couponId)) {
  578. CouponService::checkBeforeUse($couponId, $order['prePrice'], $order['userId']);
  579. }
  580. //支付前验证订单有效性
  581. OrderService::checkBeforePay($order);
  582. $name = isset($order['orderName']) && !empty($order['orderName']) ? $order['orderName'] : '购买商品';
  583. $totalFee = $order['realPrice'];
  584. //小程序使用miniOpenId
  585. if (httpUtil::isMiniProgram()) {
  586. $openId = $this->user['miniOpenId'];
  587. } else {
  588. $openId = $this->user['openId'];
  589. }
  590. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  591. //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
  592. $wxPayType = 0;
  593. if (httpUtil::isMiniProgram()) {
  594. $wxPayType = 1;
  595. }
  596. $attach = "couponId=" . $couponId . "&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType;
  597. //订单30分钟后过期
  598. $now = time();
  599. $expireTime = $now + 1800;
  600. $wx = Yii::getAlias("@vendor/weixin");
  601. require_once($wx . '/lib/WxPay.Api.php');
  602. require_once($wx . '/example/WxPay.JsApiPay.php');
  603. $input = new \WxPayUnifiedOrder();
  604. $input->SetBody($name);
  605. $input->SetOut_trade_no($orderSn);
  606. $input->SetTotal_fee($totalFee * 100);
  607. $input->SetTime_start(date("YmdHis", $now));
  608. $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
  609. $input->SetTime_expire(date("YmdHis", $expireTime));
  610. $input->SetNotify_url(Yii::$app->params['hdHost'] . '/notice/wx-callback/');
  611. $input->SetTrade_type("JSAPI");
  612. //花卉宝代为申请的微信支付
  613. $merchantExtend = $this->sjExtend->attributes;
  614. if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
  615. $input->SetSub_openid($openId);
  616. } else {
  617. $input->SetOpenid($openId);
  618. }
  619. //小程序使用miniAppId
  620. if (httpUtil::isMiniProgram()) {
  621. $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
  622. }
  623. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
  624. $tools = new \JsApiPay();
  625. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
  626. $newParams = json_decode($jsApiParameters, true);
  627. //已请求微信不能修改价格
  628. $updateData = [];
  629. $updateData['modPrice'] = 0;
  630. if (empty($order['deadline'])) {
  631. $updateData['deadline'] = $expireTime;
  632. }
  633. OrderService::updateById($orderId, $updateData);
  634. util::success($newParams);
  635. }
  636. //快捷付款订单
  637. public function actionFastPay()
  638. {
  639. ini_set('date.timezone', 'Asia/Shanghai');
  640. $post = Yii::$app->request->post();
  641. $payWay = isset($post['payWay']) ? $post['payWay'] : 0;
  642. $shopId = !empty($this->shopId) ? $this->shopId : ShopService::getDefaultShopId($this->sj);
  643. //验证门店是否有效
  644. $shopInfo = ShopService::getById($shopId);
  645. ShopService::valid($shopInfo, $this->sjId);
  646. $post['shopId'] = $shopId;
  647. //默认门店订单
  648. $store = isset($post['store']) ? $post['store'] : 1;
  649. $post['store'] = $store;
  650. //来源 0微信 1支付宝 2小程序 3朋友圈 4美团
  651. $sourceType = $this->isWx ? 0 : 1;
  652. if (httpUtil::isMiniProgram()) {
  653. $sourceType = 2;
  654. }
  655. $sourceType = isset($post['sourceType']) ? $post['sourceType'] : 0;
  656. //兼容旧系统sourceType=3表示朋友圈来源
  657. $fromType = $sourceType == 3 ? 2 : 0;
  658. $fromType = isset($post['fromType']) && !empty($post['fromType']) ? $post['fromType'] : $fromType;
  659. $post['userId'] = $this->adminId;
  660. $custom = $this->custom;
  661. $post['bookName'] = $custom['userName'] ?? '';
  662. $bookMobile = isset($post['bookMobile']) && !empty($post['bookMobile']) && stringUtil::isMobile($post['bookMobile']) ? $post['bookMobile'] : '';
  663. $bookMobile = empty($bookMobile) && isset($custom['mobile']) && !empty($custom['mobile']) ? $custom['mobile'] : $bookMobile;
  664. $post['bookMobile'] = $bookMobile;
  665. $prePrice = round($post['prePrice'], 2);
  666. $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
  667. $discountData = OrderService::getDiscountPrice(['price' => $prePrice, 'sourceType' => $sourceType, 'couponId' => $couponId, 'userId' => $this->adminId]);
  668. $actPrice = $discountData['price'];
  669. $post['discountType'] = $discountData['discountType'];
  670. $post['discountAmount'] = $discountData['discountAmount'];
  671. $post['actPrice'] = $actPrice;
  672. $post['realPrice'] = $actPrice;
  673. $post['payStyle'] = 0;
  674. $post['sjId'] = $this->sjId;
  675. $now = time();
  676. $expireTime = $now + 300;//订单5分钟后过期
  677. $post['createTime'] = date("Y-m-d H:i:s", $now);
  678. $post['deadline'] = $expireTime;
  679. if ($actPrice <= 0) {
  680. util::fail('请填写正确的金额');
  681. }
  682. //微信支付订单提交不能修改价格
  683. $post['modPrice'] = $this->isWx ? 0 : 1;
  684. $post['sourceType'] = $sourceType;
  685. $post['goodsNum'] = 1;
  686. $post['fromType'] = $fromType;
  687. $order = OrderService::addOrder($post);
  688. $orderId = $order['id'];
  689. $orderSn = $order['orderSn'];
  690. $sjId = $this->sjId;
  691. if ($payWay == 0) {
  692. $orderId = $order['id'];
  693. $name = '购买商品';
  694. $totalFee = $actPrice;
  695. $user = UserService::getById($this->adminId);
  696. $openId = isset($user['openId']) ? $user['openId'] : 0;
  697. if (httpUtil::isMiniProgram()) {
  698. //小程序使用miniOpenId
  699. $openId = $user['miniOpenId'];
  700. }
  701. if (empty($openId)) {
  702. util::fail('没有找到客户的openId');
  703. }
  704. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  705. //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
  706. $wxPayType = 0;
  707. if (httpUtil::isMiniProgram()) {
  708. $wxPayType = 1;
  709. }
  710. $attach = 'capitalType=' . $capitalType . '&couponId=' . $couponId . '&wxPayType=' . $wxPayType;
  711. $wx = Yii::getAlias("@vendor/weixin");
  712. require_once($wx . '/lib/WxPay.Api.php');
  713. require_once($wx . '/example/WxPay.JsApiPay.php');
  714. $input = new \WxPayUnifiedOrder();
  715. $input->SetBody($name);
  716. $input->SetOut_trade_no($orderSn);
  717. $input->SetTotal_fee($totalFee * 100);
  718. $input->SetTime_start(date("YmdHis", $now));
  719. $input->SetAttach($attach);
  720. //设置订单有效期5分钟
  721. $input->SetTime_expire(date("YmdHis", $expireTime));
  722. $input->SetNotify_url(Yii::$app->params['hdHost'] . '/notice/wx-callback/');
  723. $input->SetTrade_type("JSAPI");
  724. //花卉宝代为申请的微信支付
  725. $merchantExtend = $this->sjExtend->attributes;
  726. if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
  727. $input->SetSub_openid($openId);
  728. } else {
  729. $input->SetOpenid($openId);
  730. }
  731. //小程序使用miniAppId
  732. if (httpUtil::isMiniProgram()) {
  733. $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
  734. }
  735. Yii::info('支付发起使用小程序信息' . json_encode($merchantExtend));
  736. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
  737. $tools = new \JsApiPay();
  738. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
  739. $newParams = json_decode($jsApiParameters, true);
  740. $newParams['orderId'] = $orderId;
  741. util::success($newParams);
  742. } elseif ($payWay == 1) {
  743. $extend = MerchantExtendService::getBySjId($sjId);
  744. if (isset($extend['alipayInit']) == false || $extend['alipayInit'] == 0) {
  745. util::fail('支付宝付款即将开通...');
  746. }
  747. $config = [
  748. //应用ID,您的APPID。
  749. 'app_id' => $extend['alipayPId'],
  750. //商户私钥,您的原始格式RSA私钥
  751. 'merchant_private_key' => $extend['alipayKey'],
  752. //异步通知地址
  753. 'notify_url' => Yii::$app->params['hdHost'] . "/notice/ali-callback",
  754. //同步跳转
  755. 'return_url' => "",
  756. //编码格式
  757. 'charset' => "UTF-8",
  758. //签名方式
  759. 'sign_type' => "RSA2",
  760. //支付宝网关
  761. 'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
  762. //支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
  763. 'alipay_public_key' => $extend['alipayPublicKey'],
  764. ];
  765. Yii::info(json_encode($config) . ' aplipay config');
  766. $alipayWap = Yii::getAlias("@vendor/alipayWap");
  767. require_once($alipayWap . '/wappay/service/AlipayTradeService.php');
  768. require_once($alipayWap . '/wappay/buildermodel/AlipayTradeWapPayContentBuilder.php');
  769. $totalFee = $order['realPrice'];
  770. $out_trade_no = $orderSn;//商户订单号,商户网站订单系统中唯一订单号,必填
  771. $subject = '购买商品';//订单名称,必填
  772. $total_amount = $totalFee;//付款金额,必填
  773. $body = '';//商品描述,可空
  774. $timeout_express = "1m";//超时时间
  775. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  776. $passBackParams = 'capitalType=' . $capitalType . '&couponId=' . $couponId . '&sjId=' . $sjId;//将流水类型、优惠卷传过去
  777. $passBackParams = urlencode($passBackParams);
  778. $payRequestBuilder = new \AlipayTradeWapPayContentBuilder();
  779. $payRequestBuilder->setBody($body);
  780. $payRequestBuilder->setSubject($subject);
  781. $payRequestBuilder->setOutTradeNo($out_trade_no);
  782. $payRequestBuilder->setTotalAmount($total_amount);
  783. $payRequestBuilder->setTimeExpress($timeout_express);
  784. //在异步通知时将该参数原样返回
  785. $payRequestBuilder->setPassbackParams($passBackParams);
  786. //同步通知
  787. $returnUrl = Yii::$app->params['mallDomain'] . "/#/pages/callback/success?account={$sjId}&shopId={$shopId}&orderSn={$orderSn}&totalPrice={$totalFee}&pageStatus=3&payDiscountPrice=0&payDiscountType=0";
  788. //异步通知
  789. $notifyUrl = Yii::$app->params['mallHost'] . "/notice/ali-callback";
  790. $payResponse = new \AlipayTradeService($config);
  791. $result = $payResponse->wapPay($payRequestBuilder, $returnUrl, $notifyUrl);
  792. //直接将支付宝的html返回给前端
  793. echo $result;
  794. } elseif ($payWay == 2) {
  795. //余额支付,验证支付密码是否正确
  796. $payPassword = isset($post['payPassword']) ? $post['payPassword'] : 0;
  797. $user = UserService::getUserInfo($this->adminId);
  798. UserService::validPayPassword($payPassword, $user);
  799. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  800. $callbackParams = [];
  801. $respond = xhPayToolService::balancePay($callbackParams, $orderSn, $actPrice, $capitalType, $couponId);
  802. $balance = isset($respond['balance']) ? $respond['balance'] : 0;
  803. util::success(['discountAmount' => $discountData['discountAmount'], 'discountType' => $discountData['discountType'], 'orderSn' => $orderSn, 'orderId' => $orderId, 'balance' => $balance]);
  804. } else {
  805. util::fail('无效的支付方式');
  806. }
  807. }
  808. //订单评价
  809. public function actionComment()
  810. {
  811. $post = Yii::$app->request->post();
  812. $id = $post['id'];
  813. $order = OrderService::getById($id);
  814. OrderService::valid($order, $this->mainId);
  815. if ($order['grade'] > 0) {
  816. util::fail('您已经评过了');
  817. }
  818. OrderService::comment($post);
  819. util::complete('提交成功');
  820. }
  821. //订单详情 ssh 2019.12.16
  822. public function actionDetail()
  823. {
  824. $id = Yii::$app->request->get('id', 0);
  825. $detail = OrderClass::getFullInfo($id);
  826. OrderService::valid($detail, $this->mainId);
  827. util::success($detail);
  828. }
  829. public function actionList()
  830. {
  831. $get = Yii::$app->request->get();
  832. $search = isset($get['searchText']) ? $get['searchText'] : '';
  833. $searchType = isset($get['searchType']) && is_numeric($get['searchType']) ? $get['searchType'] : '';
  834. $shopId = $this->shopId ?? 0;
  835. if (empty($shopId)) {
  836. //没有登录不显示数据
  837. util::success(['list' => [], 'moreData' => 0, 'shop' => [], 'totalNum' => 0, 'totalPage' => 0]);
  838. }
  839. $where = [];
  840. $where['shopId'] = $shopId;
  841. $status = $get['status'] ?? 0;
  842. if (!empty($status)) {
  843. $where['status'] = $get['status'];
  844. }
  845. $debt = $get['debt'] ?? 2;
  846. if ($debt != 2) {
  847. $where['debt'] = $debt;
  848. }
  849. if (isset($get['shopAdminId']) && !empty($get['shopAdminId'])) {
  850. $where['shopAdminId'] = $get['shopAdminId'];
  851. }
  852. if (!empty($search)) {
  853. if (is_numeric($searchType)) {
  854. if ($searchType == 0) {
  855. $where['actPrice'] = $search;
  856. } elseif ($searchType == 1) {
  857. $where['orderSn'] = $search;
  858. } elseif ($searchType == 2) {
  859. $where['bookMobile'] = $search;
  860. } elseif ($searchType == 3) {
  861. $where['customName'] = ['like', $search];
  862. } else {
  863. $where['actPrice'] = $search;
  864. }
  865. } else {
  866. //兼容旧版本
  867. if (stringUtil::isMobile($search)) {
  868. $where['bookMobile'] = $search;
  869. } else {
  870. $where['orderSn'] = strtoupper($search);
  871. }
  872. }
  873. }
  874. $searchTime = $get['searchTime'] ?? '';
  875. if (!empty($searchTime)) {
  876. $startTime = $get['startTime'] ?? '';
  877. $endTime = $get['endTime'] ?? '';
  878. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  879. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  880. }
  881. $list = OrderService::getOrderList($where);
  882. $list['shop'] = $this->shop->attributes ?? [];
  883. util::success($list);
  884. }
  885. //订单归类 ssh 2019.12.17
  886. public function actionClassify()
  887. {
  888. $post = Yii::$app->request->post();
  889. $id = isset($post['id']) ? $post['id'] : 0;
  890. $order = OrderService::getById($id);
  891. OrderService::valid($order, $this->mainId);
  892. $categoryId = isset($post['categoryId']) ? $post['categoryId'] : $post['categoryId'];
  893. $usageId = isset($post['usageId']) ? $post['usageId'] : $post['usageId'];
  894. OrderService::classify($id, $categoryId, $usageId);
  895. util::complete();
  896. }
  897. //更新配送单 ssh 2019.12.17
  898. public function actionUpdateSheet()
  899. {
  900. $post = Yii::$app->request->post();
  901. $id = isset($post['id']) ? $post['id'] : 0;
  902. unset($post['id']);
  903. $order = OrderService::getById($id);
  904. OrderService::valid($order, $this->mainId);
  905. OrderService::updateSheet($order, $post);
  906. util::complete('提交成功');
  907. }
  908. //商家收款与发货 ssh 2019.12.18
  909. public function actionGathering()
  910. {
  911. $post = Yii::$app->request->post();
  912. $price = isset($post['price']) && is_numeric($post['price']) ? $post['price'] : 0;
  913. $payWay = isset($post['payWay']) && is_numeric($post['payWay']) ? $post['payWay'] : 0;
  914. $userId = isset($post['userId']) ? $post['userId'] : 0;
  915. $userInfo = UserService::getById($userId);
  916. if (empty($userInfo) || $userInfo['sjId'] != $this->sjId) {
  917. util::fail('您选择的客户无效');
  918. }
  919. if ($price <= 0) {
  920. util::fail('请输入金额');
  921. }
  922. $post['prePrice'] = $price;
  923. $post['actPrice'] = $price;
  924. $post['payWay'] = $payWay;
  925. $post['sourceType'] = 1;
  926. $post['userId'] = $userId;
  927. $post['goodsNum'] = 1;
  928. $post['orderName'] = '商品';
  929. $shopId = MerchantService::getDefaultShopId($this->sj);
  930. $post['shopId'] = $shopId;
  931. $order = OrderService::addOrder($post);
  932. $id = $order['id'];
  933. $orderSn = $order['orderSn'];
  934. //流水类型列表
  935. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  936. $callbackParams = [];
  937. switch ($payWay) {
  938. case 0:
  939. xhPayToolService::wxPay($callbackParams, $orderSn, $price, $capitalType, 0);
  940. break;
  941. case 1:
  942. xhPayToolService::alipay($callbackParams, $orderSn, $price, $capitalType, 0, []);
  943. break;
  944. case 2:
  945. xhPayToolService::balancePay($callbackParams, $orderSn, $price, $capitalType, 0);
  946. break;
  947. default:
  948. util::fail('无效支付方式');
  949. }
  950. util::success($order);
  951. }
  952. //免发货管理 ssh 2020.1.6
  953. public function actionWithoutSend()
  954. {
  955. $id = Yii::$app->request->get('id');
  956. $order = OrderService::getById($id);
  957. OrderService::valid($order, $this->mainId);
  958. //配送流程变更
  959. $currentFlow = OrderSendClass::withoutSend($order);
  960. util::success(['currentFlow' => $currentFlow]);
  961. }
  962. //修改价格 ssh 2020.1.6
  963. public function actionUpdatePrice()
  964. {
  965. $id = Yii::$app->request->get('id');
  966. $price = Yii::$app->request->get('price', 1);
  967. $order = OrderService::getById($id);
  968. OrderService::valid($order, $this->mainId);
  969. if (isset($order['modPrice']) && $order['modPrice'] == 0) {
  970. util::fail('已发起支付,不能修改价格');
  971. }
  972. OrderService::updateById($id, ['actPrice' => $price]);
  973. util::complete('修改成功');
  974. }
  975. //配送单 ssh 2020.2.29
  976. public function actionGetDeliverDetail()
  977. {
  978. $id = Yii::$app->request->get('id', 0);
  979. $order = OrderService::getById($id);
  980. OrderService::valid($order, $this->mainId);
  981. $reachDate = isset($order['reachDate']) && !empty($order['reachDate']) ? $order['reachDate'] : '';
  982. $reachPeriodId = $order['reachPeriod'];
  983. $reachPeriodArr = [0 => '上午', 1 => '下午', 2 => '晚上'];
  984. $reachPeriod = isset($reachPeriodArr[$reachPeriodId]) ? $reachPeriodArr[$reachPeriodId] : '';
  985. $bookName = isset($order['bookName']) ? $order['bookName'] : '';
  986. $bookMobile = isset($order['bookMobile']) ? $order['bookMobile'] : '';
  987. if (isset($order['anonymity']) && $order['anonymity'] == 1) {
  988. $bookName = '--';
  989. $bookMobile = '--';
  990. }
  991. $data = [
  992. 'reachDate' => $reachDate . ' ' . $reachPeriod,
  993. 'orderSn' => $order['orderSn'],
  994. 'receiveUserName' => $order['receiveUserName'],
  995. 'receiveMobile' => $order['receiveMobile'],
  996. 'fullAddress' => $order['fullAddress'] . "(" . $order['showAddress'] . ")",
  997. 'cardInfo' => $order['cardInfo'],
  998. 'bookMobile' => $bookMobile,
  999. 'bookName' => $bookName,
  1000. 'remark' => $order['remark'],
  1001. 'sendNum' => $order['sendNum'],
  1002. 'telephone' => 18030142050,
  1003. 'printTime' => '',
  1004. 'img' => '',
  1005. ];
  1006. util::success($data);
  1007. }
  1008. //运费计算 lqh 2021.4.12 暂反回固定
  1009. public function actionFreight()
  1010. {
  1011. util::success(['sedCost' => 10]);
  1012. }
  1013. }