OrderController.php 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113
  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. $status = $get['status'] ?? 0;
  847. if (!empty($status)) {
  848. $where['status'] = $get['status'];
  849. }
  850. $debt = $get['debt'] ?? 2;
  851. if ($debt != 2) {
  852. $where['debt'] = $debt;
  853. }
  854. if (isset($get['shopAdminId']) && !empty($get['shopAdminId'])) {
  855. $where['shopAdminId'] = $get['shopAdminId'];
  856. }
  857. if (!empty($search)) {
  858. if (is_numeric($searchType)) {
  859. if ($searchType == 0) {
  860. $where['actPrice'] = $search;
  861. } elseif ($searchType == 1) {
  862. $where['orderSn'] = $search;
  863. } elseif ($searchType == 2) {
  864. $where['bookMobile'] = $search;
  865. } elseif ($searchType == 3) {
  866. $where['customName'] = ['like', $search];
  867. } else {
  868. $where['actPrice'] = $search;
  869. }
  870. } else {
  871. //兼容旧版本
  872. if (stringUtil::isMobile($search)) {
  873. $where['bookMobile'] = $search;
  874. } else {
  875. $where['orderSn'] = strtoupper($search);
  876. }
  877. }
  878. }
  879. $searchTime = $get['searchTime'] ?? '';
  880. if (!empty($searchTime)) {
  881. $startTime = $get['startTime'] ?? '';
  882. $endTime = $get['endTime'] ?? '';
  883. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  884. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  885. }
  886. $list = OrderService::getOrderList($where);
  887. $list['shop'] = $this->shop->attributes ?? [];
  888. util::success($list);
  889. }
  890. //订单归类 ssh 2019.12.17
  891. public function actionClassify()
  892. {
  893. $post = Yii::$app->request->post();
  894. $id = isset($post['id']) ? $post['id'] : 0;
  895. $order = OrderService::getById($id);
  896. OrderService::valid($order, $this->mainId);
  897. $categoryId = isset($post['categoryId']) ? $post['categoryId'] : $post['categoryId'];
  898. $usageId = isset($post['usageId']) ? $post['usageId'] : $post['usageId'];
  899. OrderService::classify($id, $categoryId, $usageId);
  900. util::complete();
  901. }
  902. //更新配送单 ssh 2019.12.17
  903. public function actionUpdateSheet()
  904. {
  905. $post = Yii::$app->request->post();
  906. $id = isset($post['id']) ? $post['id'] : 0;
  907. unset($post['id']);
  908. $order = OrderService::getById($id);
  909. OrderService::valid($order, $this->mainId);
  910. OrderService::updateSheet($order, $post);
  911. util::complete('提交成功');
  912. }
  913. //商家收款与发货 ssh 2019.12.18
  914. public function actionGathering()
  915. {
  916. $post = Yii::$app->request->post();
  917. $price = isset($post['price']) && is_numeric($post['price']) ? $post['price'] : 0;
  918. $payWay = isset($post['payWay']) && is_numeric($post['payWay']) ? $post['payWay'] : 0;
  919. $userId = isset($post['userId']) ? $post['userId'] : 0;
  920. $userInfo = UserService::getById($userId);
  921. if (empty($userInfo) || $userInfo['sjId'] != $this->sjId) {
  922. util::fail('您选择的客户无效');
  923. }
  924. if ($price <= 0) {
  925. util::fail('请输入金额');
  926. }
  927. $post['prePrice'] = $price;
  928. $post['actPrice'] = $price;
  929. $post['payWay'] = $payWay;
  930. $post['sourceType'] = 1;
  931. $post['userId'] = $userId;
  932. $post['goodsNum'] = 1;
  933. $post['orderName'] = '商品';
  934. $shopId = MerchantService::getDefaultShopId($this->sj);
  935. $post['shopId'] = $shopId;
  936. $order = OrderService::addOrder($post);
  937. $id = $order['id'];
  938. $orderSn = $order['orderSn'];
  939. //流水类型列表
  940. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  941. $callbackParams = [];
  942. switch ($payWay) {
  943. case 0:
  944. xhPayToolService::wxPay($callbackParams, $orderSn, $price, $capitalType, 0);
  945. break;
  946. case 1:
  947. xhPayToolService::alipay($callbackParams, $orderSn, $price, $capitalType, 0, []);
  948. break;
  949. case 2:
  950. xhPayToolService::balancePay($callbackParams, $orderSn, $price, $capitalType, 0);
  951. break;
  952. default:
  953. util::fail('无效支付方式');
  954. }
  955. util::success($order);
  956. }
  957. //免发货管理 ssh 2020.1.6
  958. public function actionWithoutSend()
  959. {
  960. $id = Yii::$app->request->get('id');
  961. $order = OrderService::getById($id);
  962. OrderService::valid($order, $this->mainId);
  963. //配送流程变更
  964. $currentFlow = OrderSendClass::withoutSend($order);
  965. util::success(['currentFlow' => $currentFlow]);
  966. }
  967. //修改价格 ssh 2020.1.6
  968. public function actionUpdatePrice()
  969. {
  970. $id = Yii::$app->request->get('id');
  971. $price = Yii::$app->request->get('price', 1);
  972. $order = OrderService::getById($id);
  973. OrderService::valid($order, $this->mainId);
  974. if (isset($order['modPrice']) && $order['modPrice'] == 0) {
  975. util::fail('已发起支付,不能修改价格');
  976. }
  977. OrderService::updateById($id, ['actPrice' => $price]);
  978. util::complete('修改成功');
  979. }
  980. //配送单 ssh 2020.2.29
  981. public function actionGetDeliverDetail()
  982. {
  983. $id = Yii::$app->request->get('id', 0);
  984. $order = OrderService::getById($id);
  985. OrderService::valid($order, $this->mainId);
  986. $reachDate = isset($order['reachDate']) && !empty($order['reachDate']) ? $order['reachDate'] : '';
  987. $reachPeriodId = $order['reachPeriod'];
  988. $reachPeriodArr = [0 => '上午', 1 => '下午', 2 => '晚上'];
  989. $reachPeriod = isset($reachPeriodArr[$reachPeriodId]) ? $reachPeriodArr[$reachPeriodId] : '';
  990. $bookName = isset($order['bookName']) ? $order['bookName'] : '';
  991. $bookMobile = isset($order['bookMobile']) ? $order['bookMobile'] : '';
  992. if (isset($order['anonymity']) && $order['anonymity'] == 1) {
  993. $bookName = '--';
  994. $bookMobile = '--';
  995. }
  996. $data = [
  997. 'reachDate' => $reachDate . ' ' . $reachPeriod,
  998. 'orderSn' => $order['orderSn'],
  999. 'receiveUserName' => $order['receiveUserName'],
  1000. 'receiveMobile' => $order['receiveMobile'],
  1001. 'fullAddress' => $order['fullAddress'] . "(" . $order['showAddress'] . ")",
  1002. 'cardInfo' => $order['cardInfo'],
  1003. 'bookMobile' => $bookMobile,
  1004. 'bookName' => $bookName,
  1005. 'remark' => $order['remark'],
  1006. 'sendNum' => $order['sendNum'],
  1007. 'telephone' => 18030142050,
  1008. 'printTime' => '',
  1009. 'img' => '',
  1010. ];
  1011. util::success($data);
  1012. }
  1013. //运费计算 lqh 2021.4.12 暂反回固定
  1014. public function actionFreight()
  1015. {
  1016. util::success(['sedCost' => 10]);
  1017. }
  1018. }