OrderController.php 46 KB

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