OrderController.php 46 KB

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