OrderController.php 45 KB

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