OrderController.php 46 KB

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