OrderController.php 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672
  1. <?php
  2. namespace hd\controllers;
  3. use bizHd\hb\classes\HbClass;
  4. use Yii;
  5. use biz\shop\classes\ShopExtClass;
  6. use biz\sj\services\MerchantExtendService;
  7. use biz\sj\services\MerchantService;
  8. use bizHd\custom\classes\CustomClass;
  9. use bizHd\custom\classes\HdClass;
  10. use bizHd\distribution\classes\DistributionCommissionClass;
  11. use bizHd\goods\classes\GoodsClass;
  12. use bizHd\merchant\services\ShopService;
  13. use bizHd\order\classes\OrderClass;
  14. use bizHd\order\classes\OrderForwardClass;
  15. use bizHd\order\classes\OrderItemClass;
  16. use bizHd\order\classes\OrderSendClass;
  17. use hd\models\order\CreateOrderForm;
  18. use bizHd\express\classes\HdDeliveryOrderClass;
  19. use bizHd\order\services\OrderService;
  20. use bizHd\product\classes\ProductClass;
  21. use bizHd\saas\services\RegionService;
  22. use bizHd\shop\classes\ShopClass;
  23. use bizHd\user\services\UserService;
  24. use bizHd\work\classes\WorkClass;
  25. use common\components\dict;
  26. use common\components\dateUtil;
  27. use common\components\noticeUtil;
  28. use common\components\orderSn;
  29. use common\components\payUtil;
  30. use common\services\xhPayToolService;
  31. use common\components\util;
  32. use common\components\stringUtil;
  33. use bizHd\promote\services\CouponService;
  34. use common\components\httpUtil;
  35. use biz\wx\classes\WxMessageClass;
  36. use common\components\lakala\Lakala;
  37. use yii\helpers\ArrayHelper;
  38. class OrderController extends BaseController
  39. {
  40. public $guestAccess = ['order-relate', 'fast-pay', 'create-order', 'list', 'info'];
  41. public function actionDebt()
  42. {
  43. $get = Yii::$app->request->get();
  44. $id = $get['id'] ?? 0;
  45. $info = OrderClass::getById($id, true);
  46. if (empty($info)) {
  47. util::fail('没有找到订单');
  48. }
  49. if ($info->mainId != $this->mainId) {
  50. util::fail('不是你的订单');
  51. }
  52. //4秒内不允许重复提交
  53. util::checkRepeatCommit($id, 4);
  54. if ($info->status != 1) {
  55. util::fail('订单已付款或取消');
  56. }
  57. $payWay = dict::getDict('payWay', 'debtPay');
  58. $connection = Yii::$app->db;
  59. $transaction = $connection->beginTransaction();
  60. try {
  61. $actPrice = $info->actPrice ?? 0;
  62. $info->debtPrice = $actPrice;
  63. $info->remainDebtPrice = $actPrice;
  64. $info->debt = 1;
  65. $info->save();
  66. OrderClass::payAfter($info, $payWay);
  67. //到店自取订单,并且是待取货状态,则自动完成取货,多处要同步修改,关键词 reach_shop_fetch_goods
  68. if ($info->getGoods == 1 && $info->sendType == 1 && $info->status == 2) {
  69. $info->status = 4;
  70. $info->save();
  71. DistributionCommissionClass::onRetailOrderCompleted((int)$info->id);
  72. }
  73. $transaction->commit();
  74. //付款成功了,通知发跑腿功能,关键词 hd_pay_after_call_pt,多处要同步修改
  75. HdDeliveryOrderClass::payAfter($info);
  76. util::complete('赊账成功');
  77. } catch (\Exception $exception) {
  78. $transaction->rollBack();
  79. Yii::info("赊账失败原因:" . $exception->getMessage());
  80. util::fail('操作失败');
  81. }
  82. }
  83. //取消订单 ssh 20221231
  84. public function actionCancel()
  85. {
  86. $shopAdmin = $this->shopAdmin;
  87. //避免重复提交
  88. $adminId = $this->adminId;
  89. util::checkRepeatCommit($adminId, 3);
  90. $get = Yii::$app->request->get();
  91. $cashier = $get['cashier'] ?? 0;
  92. //是否强制取消订单 0不要强制 1强制,没有关单成功也要取消
  93. $forceCancel = $get['forceCancel'] ?? 0;
  94. $id = $get['id'] ?? 0;
  95. $order = OrderClass::getById($id, true);
  96. if ($order->mainId != $this->mainId) {
  97. util::fail('不是你的订单');
  98. }
  99. //如果收银台的订单,取消时要关闭拉卡拉的订单
  100. if ($cashier == 1) {
  101. //已取消,不需要再走下面的流程
  102. if ($order->status == 5) {
  103. util::complete('已取消');
  104. }
  105. $orderSn = $order->orderSn ?? '';
  106. $shop = $this->shop;
  107. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  108. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  109. $params = [
  110. 'appid' => 'OP00002119',
  111. 'serial_no' => '018b08cfddbd',
  112. 'merchant_no' => $shop->lklSjNo,
  113. 'term_no' => $shop->lklScanTermNo,
  114. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  115. 'lklCertificatePath' => $lklCertificatePath,
  116. ];
  117. $laResource = new Lakala($params);
  118. // 1. 先查询拉卡拉侧订单状态
  119. $queryResponse = $laResource->query(['orderSn' => $orderSn]);
  120. //响应CODE为BBS00000,仅表示查到了这笔交易。交易本身的成功与否状态,要查看响应报文中的trade_state这个值
  121. if (isset($queryResponse['code']) && $queryResponse['code'] == 'BBS00000') {
  122. $tradeState = $queryResponse['resp_data']['trade_state'] ?? '';
  123. // 订单已支付,拦截取消操作
  124. if ($tradeState == 'SUCCESS') {
  125. util::fail('已付款,不能取消');
  126. }
  127. // 根据拉卡拉聚合支付文档(id=116)及实际情况,判断是否为非终态
  128. // INIT:初始化, CREATE:下单成功, DEAL:交易处理中, USERPAYING:支付中, NOTPAY:未支付
  129. $pendingStates = ['INIT', 'CREATE', 'DEAL', 'USERPAYING', 'NOTPAY'];
  130. if (in_array($tradeState, $pendingStates)) {
  131. $closeParams = ['orderSn' => $orderSn];
  132. $closeResponse = $laResource->close($closeParams);
  133. if (!isset($closeResponse['code']) || $closeResponse['code'] != 'BBS00000') {
  134. $msg = $closeResponse['msg'] ?? '关闭失败';
  135. noticeUtil::push("拉卡拉聚合支付关单失败:{$orderSn},原因:{$msg} 原单状态:{$tradeState}", '15280215347');
  136. if ($forceCancel == 0) {
  137. //返回禁止关单
  138. util::fail('取消失败,如必要请强制取消');
  139. }
  140. }else{
  141. noticeUtil::push("关单成功,订单号:{$orderSn} 原单状态:{$tradeState}", '15280215347');
  142. }
  143. }
  144. }
  145. }
  146. $connection = Yii::$app->db;
  147. $transaction = $connection->beginTransaction();
  148. try {
  149. OrderClass::setExpire($order, true, $shopAdmin);
  150. $transaction->commit();
  151. util::complete('已取消');
  152. } catch (\Exception $exception) {
  153. $transaction->rollBack();
  154. Yii::info("取消原因:" . $exception->getMessage());
  155. util::fail('取消失败');
  156. }
  157. }
  158. //修改订单 ssh 20220926
  159. public function actionUpdate()
  160. {
  161. $post = Yii::$app->request->post();
  162. $id = $post['id'] ?? 0;
  163. $order = OrderClass::getById($id, true);
  164. OrderClass::valid($order, $this->mainId);
  165. unset($post['id']);
  166. if ($order->status == 3) {
  167. util::fail('订单已配送');
  168. }
  169. if ($order->status == 4) {
  170. util::fail('订单已完成');
  171. }
  172. if ($order->status == 5) {
  173. util::fail('订单已取消');
  174. }
  175. if ($order->fromType == 4) {
  176. util::fail('请在美团APP上修改');
  177. }
  178. $address = $post['address'] ?? '';
  179. $floor = $post['floor'] ?? '';
  180. $post['fullAddress'] = $address . $floor;
  181. OrderClass::updateById($id, $post);
  182. $workList = WorkClass::getAllByCondition(['orderId' => $id], null, '*', null, true);
  183. $remark = $post['remark'] ?? '';
  184. $reachDate = $post['reachDate'] ?? '';
  185. $reachPeriod = $post['reachPeriod'] ?? '';
  186. $cardInfo = $post['cardInfo'] ?? '';
  187. $anonymity = $post['anonymity'] ?? 0;
  188. $bookName = $post['bookName'] ?? '';
  189. if (!empty($workList)) {
  190. foreach ($workList as $work) {
  191. $work->remark = $remark;
  192. $work->reachDate = $reachDate;
  193. $work->reachPeriod = $reachPeriod;
  194. $work->cardInfo = $cardInfo;
  195. $work->anonymity = $anonymity;
  196. $work->bookName = $bookName;
  197. $work->save();
  198. }
  199. }
  200. $shopExt = ShopExtClass::getByCondition(['shopId' => $this->shopId], true);
  201. ShopExtClass::orderUpdateRemind($shopExt, $order);
  202. util::complete();
  203. }
  204. //客户欠款的订单 ssh 2021.2.4
  205. public function actionDebtList()
  206. {
  207. $get = Yii::$app->request->get();
  208. $id = $get['id'] ?? 0;
  209. $info = CustomClass::getById($id, true);
  210. CustomClass::valid($info, $this->shopId);
  211. $where = ['customId' => $id, 'debt' => 1];
  212. $searchTime = $get['searchTime'] ?? '';
  213. if (!empty($searchTime)) {
  214. $startTime = $get['startTime'] ?? '';
  215. $endTime = $get['endTime'] ?? '';
  216. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  217. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  218. }
  219. $allowedPageSizes = [100, 200, 300];
  220. $pageSize = isset($get['pageSize']) && in_array((int)$get['pageSize'], $allowedPageSizes, true)
  221. ? (int)$get['pageSize'] : 100;
  222. $page = max(1, (int)($get['page'] ?? 1));
  223. $fields = ['id', 'orderSn', 'actPrice', 'addTime', 'remainDebtPrice', 'debtPrice'];
  224. Yii::$app->request->setQueryParams(array_merge($get, ['page' => $page, 'pageSize' => $pageSize]));
  225. $result = OrderClass::getList($fields, $where, 'addTime DESC');
  226. if (!empty($result['list'])) {
  227. foreach ($result['list'] as $key => $value) {
  228. $debtPrice = $value['debtPrice'] ?? 0;
  229. $remainDebtPrice = $value['remainDebtPrice'] ?? 0;
  230. $hasPayDebt = 0;
  231. if ($debtPrice > $remainDebtPrice) {
  232. $hasPayDebt = bcsub($debtPrice, $remainDebtPrice, 2);
  233. }
  234. $result['list'][$key]['hasPayDebt'] = floatval($hasPayDebt);
  235. }
  236. }
  237. $result['customInfo'] = $info;
  238. util::success($result);
  239. }
  240. //确认送达 ssh 20250902
  241. public function actionReach()
  242. {
  243. //解决重复提交
  244. util::checkRepeatCommit($this->adminId, 5);
  245. $get = Yii::$app->request->get();
  246. $id = $get['id'] ?? 0;
  247. $order = OrderClass::getById($id, true);
  248. if (empty($order)) {
  249. util::fail('没有找到订单');
  250. }
  251. OrderClass::valid($order, $this->mainId);
  252. if ($order->status == 5) {
  253. util::fail('订单已取消');
  254. }
  255. if ($order->status == 1) {
  256. util::fail('订单待付款');
  257. }
  258. if ($order->status == 2) {
  259. util::fail('订单未发货');
  260. }
  261. if ($order->status == 4) {
  262. util::fail('订单已经送到了');
  263. }
  264. if (!in_array($order->sendStatus, [-1, -4])) {
  265. util::fail('由跑腿送货,无需确认');
  266. }
  267. $order->status = 4;
  268. $order->save();
  269. DistributionCommissionClass::onRetailOrderCompleted((int)$order->id);
  270. util::complete('操作成功');
  271. }
  272. //确认取货
  273. public function actionFetch()
  274. {
  275. $get = Yii::$app->request->get();
  276. $id = $get['id'] ?? 0;
  277. //解决重复提交
  278. util::checkRepeatCommit($id . '_' . $this->adminId, 5);
  279. $order = OrderClass::getById($id, true);
  280. if (empty($order)) {
  281. util::fail('没有找到订单');
  282. }
  283. OrderClass::valid($order, $this->mainId);
  284. if ($order->status == 5) {
  285. util::fail('订单已取消');
  286. }
  287. if ($order->status == 1) {
  288. util::fail('订单待付款');
  289. }
  290. if ($order->status == 4) {
  291. util::fail('订单已取过了');
  292. }
  293. if (in_array($order->sendStatus, [-1, 0, 1, 2, 4, 5])) {
  294. util::fail('由跑腿送货,无需确认');
  295. }
  296. $order->status = 4;
  297. $successTime = date('Y-m-d H:i:s');
  298. $order->successTime = $successTime;
  299. $order->save();
  300. DistributionCommissionClass::onRetailOrderCompleted((int)$order->id, $successTime);
  301. util::complete('操作成功');
  302. }
  303. //批量确认取货 待发货的自取订单 每次500个
  304. public function actionBatchFetch()
  305. {
  306. $where = ["status" => 2, "sendType" => 1, "shopId" => $this->shopId];
  307. $orderList = OrderService::getLimitList("id", $where, 500, "id desc");
  308. $ids = ArrayHelper::getColumn($orderList, "id");
  309. OrderService::updateByIds($ids, ["status" => 4]);
  310. util::complete($ids);
  311. }
  312. //确认发货
  313. public function actionSend()
  314. {
  315. //解决重复提交
  316. util::checkRepeatCommit($this->adminId, 5);
  317. $get = Yii::$app->request->get();
  318. $id = $get['id'] ?? 0;
  319. $order = OrderClass::getById($id, true);
  320. if (empty($order)) {
  321. util::fail('没有找到订单');
  322. }
  323. OrderClass::valid($order, $this->mainId);
  324. if ($order->status != 2) {
  325. util::fail('订单不是待发货状态');
  326. }
  327. // $workList = WorkClass::getAllByCondition(['orderId' => $id], null, '*', null, true);
  328. // if (!empty($workList)) {
  329. // $unComplete = false;
  330. // foreach ($workList as $work) {
  331. // if ($work->status != 1) {
  332. // $unComplete = true;
  333. // }
  334. // }
  335. // if ($unComplete == true) {
  336. // util::fail('还有制作单没有完成');
  337. // }
  338. // }
  339. $order->status = 3;
  340. $order->save();
  341. util::complete('已发货');
  342. }
  343. //打印订单 ssh 20220601
  344. public function actionPrintOrder()
  345. {
  346. $get = Yii::$app->request->get();
  347. $id = isset($get['id']) ? $get['id'] : 0;
  348. $order = OrderClass::getById($id, true);
  349. if (empty($order)) {
  350. util::fail('没有找到订单');
  351. }
  352. if ($order->forward == 1) {
  353. util::fail('红冲订单不能打印');
  354. }
  355. OrderClass::valid($order, $this->mainId);
  356. OrderClass::onlinePrint($order, true);
  357. util::complete();
  358. }
  359. //微信和支付宝付款码支付复查 ssh 20220422
  360. public function actionCodePayCheck()
  361. {
  362. ini_set('date.timezone', 'Asia/Shanghai');
  363. header("Content-type: text/html; charset=utf-8");
  364. $get = Yii::$app->request->get();
  365. $id = isset($get['id']) ? $get['id'] : 0;
  366. util::checkRepeatCommit($id, 3);
  367. $order = OrderClass::getById($id, true);
  368. OrderClass::valid($order, $this->mainId);
  369. $orderSn = $order->orderSn ?? '';
  370. $totalFee = $order->mainPay ?? 0;
  371. if ($order->payStatus == 1) {
  372. util::success(['returnStatus' => 'SUCCESS']);
  373. }
  374. if ($order->status == 5) {
  375. util::success(['returnStatus' => 'CANCEL']);
  376. }
  377. $connection = Yii::$app->db;
  378. $transaction = $connection->beginTransaction();
  379. try {
  380. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  381. $shop = $this->shop;
  382. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  383. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  384. $params = [
  385. 'appid' => 'OP00002119',
  386. 'serial_no' => '018b08cfddbd',
  387. 'merchant_no' => $shop->lklSjNo,
  388. 'term_no' => $shop->lklScanTermNo,
  389. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  390. 'lklCertificatePath' => $lklCertificatePath,
  391. ];
  392. $laResource = new Lakala($params);
  393. $scanParams = ['orderSn' => $orderSn,];
  394. $response = $laResource->query($scanParams);
  395. if (isset($response['code']) && $response['code'] == 'BBS00000') {
  396. if (isset($response['resp_data']['trade_state']) && $response['resp_data']['trade_state'] == 'SUCCESS') {
  397. $payWayType = dict::getDict('payWay', 'wxPay');
  398. $account_type = $response['resp_data']['account_type'] ?? '';
  399. if ($account_type == 'WECHAT') {
  400. $payWayType = dict::getDict('payWay', 'wxPay');
  401. }
  402. if ($account_type == 'ALIPAY') {
  403. $payWayType = dict::getDict('payWay', 'alipay');
  404. }
  405. $transactionId = $response['resp_data']['trade_no'] ?? '';
  406. $order->onlinePay = dict::getDict('onlinePay', 'yes');
  407. $order->save();
  408. $attach = '';
  409. payUtil::thirdPay($payWayType, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  410. $transaction->commit();
  411. //解决重复通知
  412. $cacheKey = 'pay_success_notice_' . $orderSn;
  413. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  414. if (empty($has)) {
  415. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 300, 'has']);
  416. //打印小票和语音播报
  417. $newOrder = OrderClass::getById($id, true);
  418. OrderClass::onlinePrint($newOrder);
  419. ShopExtClass::hdGatheringReport($newOrder);
  420. //到店自取订单,并且是待取货状态,则自动完成取货,多处要同步修改,关键词 reach_shop_fetch_goods
  421. if ($newOrder->getGoods == 1 && $newOrder->sendType == 1 && $newOrder->status == 2) {
  422. $newOrder->status = 4;
  423. $newOrder->save();
  424. }
  425. HdDeliveryOrderClass::payAfter($newOrder);
  426. $shopId = $newOrder->shopId ?? 0;
  427. $shop = ShopClass::getById($shopId, true);
  428. WxMessageClass::gatheringIncomeInform($shop, $newOrder);
  429. }
  430. util::success(['returnStatus' => 'SUCCESS']);
  431. } else {
  432. util::complete('未知状态..');
  433. }
  434. }
  435. util::complete('未知状态..');
  436. } catch (\Exception $e) {
  437. $transaction->rollBack();
  438. util::complete('支付失败');
  439. }
  440. }
  441. //微信和支付宝付款码支付复查 ssh 20260716
  442. public function actionCodePayVerify()
  443. {
  444. ini_set('date.timezone', 'Asia/Shanghai');
  445. header("Content-type: text/html; charset=utf-8");
  446. $get = Yii::$app->request->get();
  447. $id = $get['id'] ?? 0;
  448. util::checkRepeatCommit($id, 3);
  449. $order = OrderClass::getById($id, true);
  450. OrderClass::valid($order, $this->mainId);
  451. $orderSn = $order->orderSn ?? '';
  452. $totalFee = $order->mainPay ?? 0;
  453. if ($order->payStatus == 1) {
  454. util::success(['returnStatus' => 'SUCCESS']);
  455. }
  456. if ($order->status == 5) {
  457. util::success(['returnStatus' => 'CANCEL']);
  458. }
  459. $connection = Yii::$app->db;
  460. $transaction = $connection->beginTransaction();
  461. try {
  462. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  463. $shop = $this->shop;
  464. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  465. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  466. $params = [
  467. 'appid' => 'OP00002119',
  468. 'serial_no' => '018b08cfddbd',
  469. 'merchant_no' => $shop->lklSjNo,
  470. 'term_no' => $shop->lklScanTermNo,
  471. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  472. 'lklCertificatePath' => $lklCertificatePath,
  473. ];
  474. $laResource = new Lakala($params);
  475. $scanParams = ['orderSn' => $orderSn,];
  476. $response = $laResource->query($scanParams);
  477. if (isset($response['code']) && $response['code'] == 'BBS00000') {
  478. if (isset($response['resp_data']['trade_state']) && $response['resp_data']['trade_state'] == 'SUCCESS') {
  479. $payWayType = dict::getDict('payWay', 'wxPay');
  480. $account_type = $response['resp_data']['account_type'] ?? '';
  481. if ($account_type == 'WECHAT') {
  482. $payWayType = dict::getDict('payWay', 'wxPay');
  483. }
  484. if ($account_type == 'ALIPAY') {
  485. $payWayType = dict::getDict('payWay', 'alipay');
  486. }
  487. $transactionId = $response['resp_data']['trade_no'] ?? '';
  488. $order->onlinePay = dict::getDict('onlinePay', 'yes');
  489. $order->save();
  490. $attach = '';
  491. payUtil::thirdPay($payWayType, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  492. $transaction->commit();
  493. //解决重复通知
  494. $cacheKey = 'pay_success_notice_' . $orderSn;
  495. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  496. if (empty($has)) {
  497. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 300, 'has']);
  498. //打印小票和语音播报
  499. $newOrder = OrderClass::getById($id, true);
  500. OrderClass::onlinePrint($newOrder);
  501. ShopExtClass::hdGatheringReport($newOrder);
  502. //到店自取订单,并且是待取货状态,则自动完成取货,多处要同步修改,关键词 reach_shop_fetch_goods
  503. if ($newOrder->getGoods == 1 && $newOrder->sendType == 1 && $newOrder->status == 2) {
  504. $newOrder->status = 4;
  505. $newOrder->save();
  506. }
  507. HdDeliveryOrderClass::payAfter($newOrder);
  508. $shopId = $newOrder->shopId ?? 0;
  509. $shop = ShopClass::getById($shopId, true);
  510. WxMessageClass::gatheringIncomeInform($shop, $newOrder);
  511. }
  512. util::success(['returnStatus' => 'SUCCESS']);
  513. } else {
  514. util::success(['returnStatus' => 'PENDING'], '等待支付中...');
  515. }
  516. }
  517. util::success(['returnStatus' => 'PENDING'], '等待支付中...');
  518. } catch (\Exception $e) {
  519. $transaction->rollBack();
  520. util::complete('支付失败');
  521. }
  522. }
  523. /**
  524. * 微信和支付宝付款码支付
  525. * 职责:处理商户扫描客户付款码(被扫支付)的请求,调用拉卡拉支付接口并更新本地订单状态(零售端)
  526. * 入参:GET 传参 id (订单ID), authCode (付款码), version (版本号)
  527. * 返回:JSON 格式的支付结果(SUCCESS/FAILURE)
  528. * 副作用:更新订单支付状态、支付方式,记录支付日志,触发云打印、跑腿呼叫及语音播报
  529. * 关键边界:
  530. * 1. 验证订单有效性与待付款状态
  531. * 2. 校验付款码格式(微信/支付宝)
  532. * 3. 优化:将拉卡拉外部网络请求移出数据库事务,避免因网络延迟长时间占用数据库连接和行锁
  533. */
  534. public function actionCodePay()
  535. {
  536. ini_set('date.timezone', 'Asia/Shanghai');
  537. header("Content-type: text/html; charset=utf-8");
  538. $get = Yii::$app->request->get();
  539. $id = isset($get['id']) ? $get['id'] : 0;
  540. util::checkRepeatCommit($id, 3);
  541. $version = $get['version'] ?? 0;
  542. $order = OrderClass::getById($id, true);
  543. OrderClass::valid($order, $this->mainId);
  544. if ($order->status == OrderClass::ORDER_STATUS_CANCEL) {
  545. $msg = '订单已取消';
  546. util::success(['returnStatus' => 'FAILURE'], $msg);
  547. }
  548. if ($order->status != OrderClass::ORDER_STATUS_UN_PAY) {
  549. $msg = '订单不是待付款状态';
  550. util::success(['returnStatus' => 'FAILURE'], $msg);
  551. }
  552. $shop = $this->shop;
  553. $sj = $shop->merchantName;
  554. $shopName = $shop->shopName;
  555. $name = $shopName == '首店' ? $sj : $sj . '-' . $shopName;
  556. $authCode = (string)$get['authCode'] ?? '';
  557. if ($version > 0) {
  558. if (empty($authCode)) {
  559. $msg = '没有扫到付款码';
  560. $remind = $msg . "(零售端付款码:{$authCode})" . '(' . $name . ')';
  561. noticeUtil::push($remind . ' 编号005', '15280215347');
  562. util::success(['returnStatus' => 'FAILURE'], $msg);
  563. }
  564. //微信文档说明 https://pay.weixin.qq.com/doc/v2/merchant/4011936234
  565. $wxPattern = '/^(10|11|12|13|14|15)\d{16}$/';
  566. //支付宝文档说明 https://opendocs.alipay.com/open/194/106039/
  567. $aliPattern = '/^(25|26|27|28|29|30)\d{14,22}$/';
  568. if (!preg_match($wxPattern, $authCode) && !preg_match($aliPattern, $authCode)) {
  569. $msg = '付款码错误,请使用微信或支付宝付款码';
  570. $remind = $msg . "(零售端付款码:{$authCode})" . '(' . $name . ')';
  571. //noticeUtil::push($remind . ' 编号009', '15280215347');
  572. util::success(['returnStatus' => 'FAILURE'], $msg);
  573. }
  574. } else {
  575. if (empty($authCode)) {
  576. util::fail('没有获取到支付码');
  577. }
  578. }
  579. $orderSn = $order->orderSn ?? '';
  580. $lsCodePayErrorKey = 'ls_code_pay_error_' . $id;
  581. $hasFailPay = Yii::$app->redis->executeCommand('GET', [$lsCodePayErrorKey]);
  582. //前面有付失败过,要重新生成单号
  583. if (!empty($hasFailPay)) {
  584. $oldOrderSn = $order->orderSn;
  585. $orderSn = orderSn::getOrderSn();
  586. $order->orderSn = $orderSn;
  587. $order->save();
  588. OrderItemClass::updateByCondition(['orderSn' => $oldOrderSn], ['orderSn' => $orderSn]);
  589. }
  590. $subject = '购买花材 ' . $orderSn;
  591. $totalFee = $order->mainPay ?? 0;
  592. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  593. try {
  594. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  595. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  596. $params = [
  597. 'appid' => 'OP00002119',
  598. 'serial_no' => '018b08cfddbd',
  599. 'merchant_no' => $shop->lklSjNo,
  600. 'term_no' => $shop->lklScanTermNo,
  601. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  602. 'lklCertificatePath' => $lklCertificatePath,
  603. ];
  604. $laResource = new Lakala($params);
  605. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
  606. $scanParams = [
  607. 'orderSn' => $orderSn,
  608. 'amount' => $totalFee,
  609. 'capitalType' => $capitalType,
  610. 'notifyUrl' => $notifyUrl,
  611. 'subject' => $subject,
  612. 'authCode' => $authCode,
  613. ];
  614. // 复杂分支/关键逻辑:在调用外部支付接口前不开启事务,防止网络延迟卡死数据库连接
  615. $response = $laResource->scanPay($scanParams);
  616. if (isset($response['code']) && $response['code'] == 'BBS00000') {
  617. // 复杂分支/关键逻辑:支付成功后,开启数据库事务,确保本地订单状态更新的原子性
  618. $connection = Yii::$app->db;
  619. $transaction = $connection->beginTransaction();
  620. try {
  621. $account_type = $response['resp_data']['account_type'] ?? '';
  622. $payWayType = dict::getDict('payWay', 'wxPay');
  623. if ($account_type == 'WECHAT') {
  624. $payWayType = dict::getDict('payWay', 'wxPay');
  625. }
  626. if ($account_type == 'ALIPAY') {
  627. $payWayType = dict::getDict('payWay', 'alipay');
  628. }
  629. $order->payWay = $payWayType;
  630. $transactionId = $response['resp_data']['trade_no'] ?? '';
  631. $order->onlinePay = dict::getDict('onlinePay', 'yes');
  632. $order->save();
  633. $attach = '';
  634. payUtil::thirdPay($payWayType, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
  635. $transaction->commit();
  636. } catch (\Exception $e) {
  637. $transaction->rollBack();
  638. throw $e;
  639. }
  640. //解决重复通知
  641. $cacheKey = 'hd_shop_order_pay_' . $orderSn;
  642. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  643. if (empty($has)) {
  644. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 300, 'has']);
  645. $newOrder = OrderClass::getById($id, true);
  646. //到店自取订单,并且是待取货状态,则自动完成取货,多处要同步修改,关键词 reach_shop_fetch_goods
  647. if ($newOrder->getGoods == 1 && $newOrder->sendType == 1 && $newOrder->status == 2) {
  648. $newOrder->status = 4;
  649. $newOrder->save();
  650. }
  651. //打印小票
  652. OrderClass::onlinePrint($newOrder);
  653. HdDeliveryOrderClass::payAfter($newOrder);
  654. //语音播报
  655. ShopExtClass::hdGatheringReport($newOrder);
  656. $shopId = $newOrder->shopId ?? 0;
  657. $shop = ShopClass::getById($shopId, true);
  658. WxMessageClass::gatheringIncomeInform($shop, $newOrder);
  659. }
  660. util::success(['returnStatus' => 'SUCCESS']);
  661. } else {
  662. //标记有没付成功的次数,原因有可能是余额不足等
  663. Yii::$app->redis->executeCommand('SETEX', [$lsCodePayErrorKey, 1200, 'hasFail']);
  664. $msg = $response['msg'] ?? '';
  665. $retCode = $response['code'] ?? '';
  666. $fullMsg = $msg . "(零售端付款码:{$authCode})" . '(' . $name . ')';
  667. if ($retCode == 'BBS10000' || $retCode == 'BBS11105') {
  668. $shopId = $order->shopId;
  669. ShopExtClass::remindInputPassword($shopId);
  670. }
  671. //noticeUtil::push($fullMsg . ' ' . $retCode . ' 编号008', '15280215347');
  672. util::success(['returnStatus' => 'FAILURE', 'returnCode' => $retCode], $msg);
  673. }
  674. } catch (\Exception $e) {
  675. Yii::error("零售端支付失败原因:" . $e->getMessage());
  676. util::fail('支付失败');
  677. }
  678. }
  679. //开单操作 ssh 20220316
  680. public function actionCreateOrder()
  681. {
  682. $post = Yii::$app->request->post();
  683. $post['sjId'] = $this->sjId;
  684. $post['shopId'] = $this->shopId;
  685. $post['mainId'] = $this->mainId ?? 0;
  686. $shop = $this->shop;
  687. if ($shop->memberLevelSet == 0) {
  688. //util::fail('请先设置会员等级');
  689. }
  690. $now = time();
  691. $orderValidTime = 600;
  692. $expireTime = $now + $orderValidTime;
  693. $post['deadline'] = $expireTime;
  694. $post['staffId'] = $this->shopAdminId ?? 0;
  695. $post['staffName'] = $this->shopAdmin->name ?? '';
  696. $post['flowerNum'] = isset($post['flowerNum']) && $post['flowerNum'] > 0 ? $post['flowerNum'] : 0;
  697. $version = $post['version'] ?? 0; //验证已移至 CreateOrderForm
  698. if ($version < 3) {
  699. util::fail('请升级版本,或用小程序');
  700. }
  701. //默认情况开单员工和收款员工是同个人
  702. $staffId = $this->shopAdminId ?? 0;
  703. $staffName = $this->shopAdmin->name ?? '';
  704. if (empty($post['shopAdminId'])) {
  705. $post['shopAdminId'] = $staffId;
  706. $post['shopAdminName'] = $staffName;
  707. }
  708. if (empty($post['getStaffId'])) {
  709. $post['getStaffId'] = $staffId;
  710. $post['getStaffName'] = $this->shopAdmin->name ?? '';
  711. }
  712. $groupId = !empty($post['groupId']) ? $post['groupId'] : 0;
  713. $post['fromType'] = $post['fromType'] ?? 1;
  714. if ($post['fromType'] == dict::getDict('fromType', 'friend')) {
  715. if (empty($post['bookName'])) {
  716. util::fail('请填写订花人姓名');
  717. }
  718. }
  719. $customId = $post['customId'] ?? 0;
  720. $custom = CustomClass::getById($customId, true);
  721. if (empty($custom)) {
  722. util::fail('没有找到客户哦');
  723. }
  724. $hdId = $custom->hdId ?? 0;
  725. $hd = HdClass::getById($hdId, true);
  726. if (empty($hd)) {
  727. util::fail('客户对应的花店信息缺失,编号869');
  728. }
  729. $hdName = $hd->name ?? '';
  730. $post['hdId'] = $hdId;
  731. $post['hdName'] = $hdName;
  732. $customName = $custom->name ?? '';
  733. $post['customName'] = $customName;
  734. $post['customNamePy'] = stringUtil::py($customName);
  735. if (!empty($post['receiveMobile'])) {
  736. if (!stringUtil::isMobile($post['receiveMobile'])) {
  737. util::fail('请填写正确的收花人手机号');
  738. }
  739. }
  740. if (!empty($post['bookMobile'])) {
  741. if (!stringUtil::isMobile($post['bookMobile'])) {
  742. util::fail('请填写正确的订花人手机号');
  743. }
  744. }
  745. $hasPay = $post['hasPay'] ?? dict::getDict('hasPay', 'unPay');
  746. $post['sendType'] = $post['sendType'] ?? 1;
  747. $forward = $post['forward'] ?? 0;
  748. if ($forward == 1) {
  749. if ($hasPay != 1) {
  750. util::fail('红冲订单只能走线下转账');
  751. }
  752. $historyDate = $post['historyDate'] ?? '';
  753. if (!empty($historyDate)) {
  754. if ($historyDate != date("Y-m-d")) {
  755. util::fail('红冲订单不能修改账单日期,只能今天');
  756. }
  757. }
  758. }
  759. $productJson = $post['product'] ?? '';
  760. $productList = [];
  761. if (!empty($productJson)) {
  762. $productList = json_decode($productJson, true);
  763. }
  764. if (empty($productList) && empty($groupId)) {
  765. //商家手机上开单并生成制作单
  766. if (!empty($post['unitGoodsPrice'])) {
  767. util::fail('此功能停用,有需要请联系管理员');
  768. $unitGoodsPrice = $post['unitGoodsPrice'];
  769. if (!is_numeric($unitGoodsPrice)) {
  770. util::fail('请输入正确的单价');
  771. }
  772. $productList = GoodsClass::orderCreateGoods($post);
  773. }
  774. }
  775. //直接收款
  776. $zjGathering = $post['zjGathering'] ?? 0;
  777. if ($zjGathering == 1) {
  778. $lsGoodsPrice = $post['lsGoodsPrice'] ?? 0;
  779. if (!is_numeric($lsGoodsPrice) || $lsGoodsPrice <= 0) {
  780. util::fail('请填写价格');
  781. }
  782. //直接收款不需要打印小票
  783. $post['needPrint'] = dict::getDict('needPrint', 'noNeed');
  784. $shopId = $this->shopId;
  785. $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  786. $zjGatheringItem = !empty($ext) ? $ext->zjGatheringItem : 0;
  787. if (empty($zjGatheringItem)) {
  788. util::fail('请设置直接收款的商品');
  789. }
  790. $zjGatheringItemInfo = ProductClass::getById($zjGatheringItem, true);
  791. if (empty($zjGatheringItemInfo)) {
  792. util::fail('请设置直接收款的商品哈');
  793. }
  794. $productList = [['productId' => $zjGatheringItem, 'unitType' => 0, 'num' => 1, 'property' => '1', 'unitPrice' => $lsGoodsPrice]];
  795. }
  796. $callErrand = $post['callErrand'] ?? 0;
  797. if ($callErrand == 1) {
  798. $shopId = $this->shopId;
  799. $shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  800. if (!empty($shopExt) && $shopExt->orderFlow == 0) {
  801. util::fail('下单后要变待发货,才能直接发跑腿');
  802. }
  803. }
  804. $connection = Yii::$app->db;
  805. $transaction = $connection->beginTransaction();
  806. try {
  807. $post['product'] = $productList;
  808. $reduceStock = $post['reduceStock'] ?? 0;
  809. if ($reduceStock == 1) {
  810. //如果扣除库,则走另外一条路
  811. $return = OrderClass::reduceMyStock($post, $this->shop, $custom);
  812. $transaction->commit();
  813. util::success($return);
  814. }
  815. //解决开单提交订单时,别人修改价格,造成提交价格不是真实卖价问题!!
  816. $dealPrice = $post['dealPrice'] ?? 0;
  817. //解决重复提交
  818. util::checkRepeatCommit($this->adminId . '_' . $dealPrice, 3);
  819. $totalNum = 0;
  820. if ($dealPrice == 0) {
  821. $productIds = [];
  822. $hsIds = [];
  823. foreach ($productList as $pv) {
  824. $property = $pv['property'] ?? 0;
  825. $puId = $pv['productId'] ?? 0;
  826. if ($property == 0) {
  827. $hsIds[] = $puId;
  828. } else {
  829. $productIds[] = $puId;
  830. }
  831. }
  832. $itemInfo = [];
  833. if (!empty($productIds)) {
  834. $itemInfo = ProductClass::getByIds($productIds, null, 'id');
  835. }
  836. $hsInfo = [];
  837. if (!empty($hsIds)) {
  838. $hsInfo = GoodsClass::getByIds($hsIds, null, 'id');
  839. }
  840. $diff = [];
  841. $priceMap = \bizGhs\custom\classes\CustomClass::$levelPriceKeyMap;
  842. $addPriceMap = \bizGhs\custom\classes\CustomClass::$levelAddPriceKeyMap;
  843. $level = 0;
  844. foreach ($productList as $currentProduct) {
  845. $property = $currentProduct['property'] ?? 0;
  846. $currentPrice = $currentProduct['unitPrice'] ?? 0;
  847. $currentId = $currentProduct['productId'] ?? 0;
  848. if ($property == 1) {
  849. $systemInfo = $itemInfo[$currentId] ?? [];
  850. if (!empty($systemInfo)) {
  851. $name = $systemInfo['name'] ?? '';
  852. $systemPrice = \bizGhs\product\classes\ProductClass::getFinalPrice($systemInfo, $level, $priceMap, $addPriceMap);
  853. if (floatval($currentPrice) != floatval($systemPrice)) {
  854. $diff[] = [
  855. 'name' => $name,
  856. 'price' => $systemPrice,
  857. 'kdPrice' => $currentPrice,
  858. ];
  859. }
  860. }
  861. } else {
  862. $systemInfo = $hsInfo[$currentId] ?? [];
  863. if (!empty($systemInfo)) {
  864. $params = [];
  865. $name = $systemInfo['name'] ?? '';
  866. $hsData = GoodsClass::getFinalPrice($systemInfo, $shop, $custom, $params);
  867. $systemPrice = $hsData['price'] ?? 0;
  868. if ($systemInfo['priceType'] == 1) {
  869. if (floatval($currentPrice) != floatval($systemPrice)) {
  870. $diff[] = [
  871. 'name' => $name,
  872. 'price' => $systemPrice,
  873. 'kdPrice' => $currentPrice,
  874. ];
  875. }
  876. }
  877. }
  878. }
  879. $num = $currentProduct['num'];
  880. $totalNum = bcadd($totalNum, $num);
  881. }
  882. if (!empty($diff)) {
  883. util::success(['diff' => $diff, 'respondType' => 'priceError']);
  884. }
  885. }
  886. //红包使用,多有处,关键词 use_hb_action
  887. $hbId = $post['hbId'] ?? 0;
  888. $hb = null;
  889. if ($hbId > 0) { // 不使用 $hbId =! 0,因为要用负数来表示红包已取消
  890. $hb = HbClass::getById($hbId, true);
  891. if (!empty($hb)) {
  892. if ($hb->customId != $customId) {
  893. util::fail('不是这个客户的红包');
  894. }
  895. if ($hb->amount != $post['hbAmount']) {
  896. util::fail('红包错误'); //红包数据可能被串改
  897. }
  898. if ($hb->status == 1) {
  899. util::fail('红包已使用');
  900. }
  901. if ($hb->status == -1) {
  902. util::fail('红包已作废');
  903. }
  904. if ($hb->endTime < time()) {
  905. $hb->status = -1;
  906. $hb->save();
  907. util::fail('红包已失效');
  908. }
  909. if ($hb->beginTime > time()) {
  910. util::fail('红包可使用期未到');
  911. }
  912. if ($this->shop->rechargeWeal == 3) {
  913. // 判断支付方式是否是余额支付
  914. if ($hasPay != dict::getDict('hasPay', 'balance')) {
  915. util::fail('用红包要用余额支付');
  916. } else {
  917. if ($custom->balance < $post['modifyPrice']) {
  918. util::fail('用红包要用余额支付(您的余额不足)');
  919. }
  920. }
  921. }
  922. } else {
  923. Yii::error('没有找到红包,hbId: ', $hbId . ' ' . __METHOD__);
  924. util::fail('红包无效');
  925. }
  926. }
  927. $post['bigNum'] = $totalNum;
  928. //多处调用这个方法,注意同步修改,搜索关键词 createHdNewOrder
  929. $return = OrderService::createHdOrder($post, $custom, $hasPay);
  930. if (!empty($hb)) {
  931. $hb->status = 1;
  932. $hb->orderId = $return->id;
  933. $hb->save();
  934. }
  935. $staff = $this->shopAdmin;
  936. //售后开付款单,库存要变化,关系要建立,多处需要同步修改 sh_pay_change ssh
  937. OrderClass::shPayChange($return, $shop, $staff);
  938. //打印小票和语音播报等使用
  939. $id = $return->id ?? 0;
  940. $order = OrderClass::getById($id, true);
  941. //如果需要生成制作单
  942. $needWork = $post['needWork'] ?? 0;
  943. if ($needWork == 1) {
  944. $main = $this->main;
  945. WorkClass::needWork($order, $main);
  946. $has = WorkClass::getByCondition(['orderId' => $id], true);
  947. if (!empty($has)) {
  948. $return->hasWork = 1;
  949. $return->save();
  950. }
  951. }
  952. //到店自取订单,并且是待取货状态,则自动完成取货,多处要同步修改,关键词 reach_shop_fetch_goods
  953. if ($order->getGoods == 1 && $order->sendType == 1 && $order->status == 2) {
  954. $order->status = 4;
  955. $order->save();
  956. DistributionCommissionClass::onRetailOrderCompleted((int)$order->id);
  957. }
  958. $transaction->commit();
  959. if ($order->fromType == 3 || $order->fromType == 4) {
  960. //除了客服号下单和美团下单,其它情况允许打小票
  961. } else {
  962. //前台打小票
  963. OrderClass::onlinePrint($order);
  964. }
  965. //订单发跑腿流程
  966. HdDeliveryOrderClass::prepareAskData($post, $order);
  967. //前台提示收款多少钱
  968. ShopExtClass::hdGatheringReport($order);
  969. //前台提醒出示付款码
  970. if (isset($order->status) && $order->status == 1) {
  971. if (isset($post['isCashier']) && $post['isCashier'] == 1) {
  972. ShopExtClass::pleasePayReport($order);
  973. }
  974. }
  975. $shopId = $order->shopId ?? 0;
  976. $shop = ShopClass::getById($shopId, true);
  977. WxMessageClass::gatheringIncomeInform($shop, $order);
  978. if ($needWork == 1) {
  979. //新制作单提示
  980. $shopExt = ShopExtClass::getByCondition(['shopId' => $this->shopId], true);
  981. ShopExtClass::newWorkRemind($shopExt, $order);
  982. }
  983. util::success($return);
  984. } catch (\Exception $e) {
  985. $transaction->rollBack();
  986. Yii::error("下单失败原因:" . $e->getMessage());
  987. util::fail('下单失败');
  988. }
  989. }
  990. //下单要用到的相关信息 ssh 2019.12.6
  991. public function actionOrderRelate()
  992. {
  993. $regionTree = RegionService::tree();
  994. $shop = $this->shop->attributes;
  995. $freight = MerchantExtendService::getFreight($this->sjExtend);
  996. $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
  997. $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'thirdMapKey' => $mapKey, 'merchant' => $shop];
  998. util::success($out);
  999. }
  1000. //余额支付 ssh 2019.12.6
  1001. public function actionBalancePay()
  1002. {
  1003. $post = Yii::$app->request->post();
  1004. $orderSn = $post['orderSn'] ?? 0;
  1005. $payPassword = $post['payPassword'] ?? 0;
  1006. $couponId = $post['couponId'] ?? 0;
  1007. $order = OrderService::getByOrderSn($orderSn);
  1008. $userId = $this->adminId;
  1009. $user = UserService::getUserInfo($userId);
  1010. //验证支付密码是否正确
  1011. UserService::validPayPassword($payPassword, $user);
  1012. //支付前验证订单有效性
  1013. OrderService::checkBeforePay($order);
  1014. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  1015. $totalFee = $order['prePrice'];
  1016. $sourceType = 0;
  1017. $discountData = OrderService::getDiscountPrice(['price' => $totalFee, 'sourceType' => $sourceType, 'couponId' => $couponId, 'userId' => $this->adminId]);
  1018. $actPrice = $discountData['price'];
  1019. $callbackParams = [];
  1020. $respond = xhPayToolService::balancePay($callbackParams, $orderSn, $actPrice, $capitalType, $couponId);
  1021. $balance = $respond['balance'] ?? 0;
  1022. util::success(['discountAmount' => $discountData['discountAmount'], 'discountType' => $discountData['discountType'], 'balance' => $balance]);
  1023. }
  1024. //获取商城下单要用的微信支付和小程序支付参数 ssh 2019.21.3
  1025. public function actionWxPay()
  1026. {
  1027. ini_set('date.timezone', 'Asia/Shanghai');
  1028. $post = Yii::$app->request->post();
  1029. $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
  1030. $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
  1031. $order = OrderService::getByOrderSn($orderSn);
  1032. $orderId = $order['id'];
  1033. //验证优惠券是否还有效
  1034. if (!empty($couponId)) {
  1035. CouponService::checkBeforeUse($couponId, $order['prePrice'], $order['userId']);
  1036. }
  1037. //支付前验证订单有效性
  1038. OrderService::checkBeforePay($order);
  1039. $name = isset($order['orderName']) && !empty($order['orderName']) ? $order['orderName'] : '购买商品';
  1040. $totalFee = $order['realPrice'];
  1041. //小程序使用miniOpenId
  1042. if (httpUtil::isMiniProgram()) {
  1043. $openId = $this->user['miniOpenId'];
  1044. } else {
  1045. $openId = $this->user['openId'];
  1046. }
  1047. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  1048. //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
  1049. $wxPayType = 0;
  1050. if (httpUtil::isMiniProgram()) {
  1051. $wxPayType = 1;
  1052. }
  1053. $attach = "couponId=" . $couponId . "&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType;
  1054. //订单30分钟后过期
  1055. $now = time();
  1056. $expireTime = $now + 1800;
  1057. $wx = Yii::getAlias("@vendor/weixin");
  1058. require_once($wx . '/lib/WxPay.Api.php');
  1059. require_once($wx . '/example/WxPay.JsApiPay.php');
  1060. $input = new \WxPayUnifiedOrder();
  1061. $input->SetBody($name);
  1062. $input->SetOut_trade_no($orderSn);
  1063. $input->SetTotal_fee($totalFee * 100);
  1064. $input->SetTime_start(date("YmdHis", $now));
  1065. $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
  1066. $input->SetTime_expire(date("YmdHis", $expireTime));
  1067. $input->SetNotify_url(Yii::$app->params['hdHost'] . '/notice/wx-callback/');
  1068. $input->SetTrade_type("JSAPI");
  1069. //花卉宝代为申请的微信支付
  1070. $merchantExtend = $this->sjExtend->attributes;
  1071. if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
  1072. $input->SetSub_openid($openId);
  1073. } else {
  1074. $input->SetOpenid($openId);
  1075. }
  1076. //小程序使用miniAppId
  1077. if (httpUtil::isMiniProgram()) {
  1078. $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
  1079. }
  1080. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
  1081. $tools = new \JsApiPay();
  1082. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
  1083. $newParams = json_decode($jsApiParameters, true);
  1084. //已请求微信不能修改价格
  1085. $updateData = [];
  1086. $updateData['modPrice'] = 0;
  1087. if (empty($order['deadline'])) {
  1088. $updateData['deadline'] = $expireTime;
  1089. }
  1090. OrderService::updateById($orderId, $updateData);
  1091. util::success($newParams);
  1092. }
  1093. //快捷付款订单
  1094. public function actionFastPay()
  1095. {
  1096. ini_set('date.timezone', 'Asia/Shanghai');
  1097. $post = Yii::$app->request->post();
  1098. $payWay = isset($post['payWay']) ? $post['payWay'] : 0;
  1099. $shopId = !empty($this->shopId) ? $this->shopId : ShopService::getDefaultShopId($this->sj);
  1100. //验证门店是否有效
  1101. $shopInfo = ShopService::getById($shopId);
  1102. ShopService::valid($shopInfo, $this->sjId);
  1103. $post['shopId'] = $shopId;
  1104. //默认门店订单
  1105. $store = isset($post['store']) ? $post['store'] : 1;
  1106. $post['store'] = $store;
  1107. //来源 0微信 1支付宝 2小程序 3朋友圈 4美团
  1108. $sourceType = $this->isWx ? 0 : 1;
  1109. if (httpUtil::isMiniProgram()) {
  1110. $sourceType = 2;
  1111. }
  1112. $sourceType = isset($post['sourceType']) ? $post['sourceType'] : 0;
  1113. //兼容旧系统sourceType=3表示朋友圈来源
  1114. $fromType = $sourceType == 3 ? 2 : 0;
  1115. $fromType = isset($post['fromType']) && !empty($post['fromType']) ? $post['fromType'] : $fromType;
  1116. $post['userId'] = $this->adminId;
  1117. $custom = $this->custom;
  1118. $post['bookName'] = $custom['userName'] ?? '';
  1119. $bookMobile = isset($post['bookMobile']) && !empty($post['bookMobile']) && stringUtil::isMobile($post['bookMobile']) ? $post['bookMobile'] : '';
  1120. $bookMobile = empty($bookMobile) && isset($custom['mobile']) && !empty($custom['mobile']) ? $custom['mobile'] : $bookMobile;
  1121. $post['bookMobile'] = $bookMobile;
  1122. $prePrice = round($post['prePrice'], 2);
  1123. $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
  1124. $discountData = OrderService::getDiscountPrice(['price' => $prePrice, 'sourceType' => $sourceType, 'couponId' => $couponId, 'userId' => $this->adminId]);
  1125. $actPrice = $discountData['price'];
  1126. $post['discountType'] = $discountData['discountType'];
  1127. $post['discountAmount'] = $discountData['discountAmount'];
  1128. $post['actPrice'] = $actPrice;
  1129. $post['realPrice'] = $actPrice;
  1130. $post['payStyle'] = 0;
  1131. $post['sjId'] = $this->sjId;
  1132. $now = time();
  1133. $expireTime = $now + 300;//订单5分钟后过期
  1134. $post['createTime'] = date("Y-m-d H:i:s", $now);
  1135. $post['deadline'] = $expireTime;
  1136. if ($actPrice <= 0) {
  1137. util::fail('请填写正确的金额');
  1138. }
  1139. //微信支付订单提交不能修改价格
  1140. $post['modPrice'] = $this->isWx ? 0 : 1;
  1141. $post['sourceType'] = $sourceType;
  1142. $post['goodsNum'] = 1;
  1143. $post['fromType'] = $fromType;
  1144. $order = OrderService::addOrder($post);
  1145. $orderId = $order['id'];
  1146. $orderSn = $order['orderSn'];
  1147. $sjId = $this->sjId;
  1148. if ($payWay == 0) {
  1149. $orderId = $order['id'];
  1150. $name = '购买商品';
  1151. $totalFee = $actPrice;
  1152. $user = UserService::getById($this->adminId);
  1153. $openId = isset($user['openId']) ? $user['openId'] : 0;
  1154. if (httpUtil::isMiniProgram()) {
  1155. //小程序使用miniOpenId
  1156. $openId = $user['miniOpenId'];
  1157. }
  1158. if (empty($openId)) {
  1159. util::fail('没有找到客户的openId');
  1160. }
  1161. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  1162. //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
  1163. $wxPayType = 0;
  1164. if (httpUtil::isMiniProgram()) {
  1165. $wxPayType = 1;
  1166. }
  1167. $attach = 'capitalType=' . $capitalType . '&couponId=' . $couponId . '&wxPayType=' . $wxPayType;
  1168. $wx = Yii::getAlias("@vendor/weixin");
  1169. require_once($wx . '/lib/WxPay.Api.php');
  1170. require_once($wx . '/example/WxPay.JsApiPay.php');
  1171. $input = new \WxPayUnifiedOrder();
  1172. $input->SetBody($name);
  1173. $input->SetOut_trade_no($orderSn);
  1174. $input->SetTotal_fee($totalFee * 100);
  1175. $input->SetTime_start(date("YmdHis", $now));
  1176. $input->SetAttach($attach);
  1177. //设置订单有效期5分钟
  1178. $input->SetTime_expire(date("YmdHis", $expireTime));
  1179. $input->SetNotify_url(Yii::$app->params['hdHost'] . '/notice/wx-callback/');
  1180. $input->SetTrade_type("JSAPI");
  1181. //花卉宝代为申请的微信支付
  1182. $merchantExtend = $this->sjExtend->attributes;
  1183. if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
  1184. $input->SetSub_openid($openId);
  1185. } else {
  1186. $input->SetOpenid($openId);
  1187. }
  1188. //小程序使用miniAppId
  1189. if (httpUtil::isMiniProgram()) {
  1190. $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
  1191. }
  1192. Yii::info('支付发起使用小程序信息' . json_encode($merchantExtend));
  1193. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
  1194. $tools = new \JsApiPay();
  1195. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
  1196. $newParams = json_decode($jsApiParameters, true);
  1197. $newParams['orderId'] = $orderId;
  1198. util::success($newParams);
  1199. } elseif ($payWay == 1) {
  1200. $extend = MerchantExtendService::getBySjId($sjId);
  1201. if (isset($extend['alipayInit']) == false || $extend['alipayInit'] == 0) {
  1202. util::fail('支付宝付款即将开通...');
  1203. }
  1204. $config = [
  1205. //应用ID,您的APPID。
  1206. 'app_id' => $extend['alipayPId'],
  1207. //商户私钥,您的原始格式RSA私钥
  1208. 'merchant_private_key' => $extend['alipayKey'],
  1209. //异步通知地址
  1210. 'notify_url' => Yii::$app->params['hdHost'] . "/notice/ali-callback",
  1211. //同步跳转
  1212. 'return_url' => "",
  1213. //编码格式
  1214. 'charset' => "UTF-8",
  1215. //签名方式
  1216. 'sign_type' => "RSA2",
  1217. //支付宝网关
  1218. 'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
  1219. //支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
  1220. 'alipay_public_key' => $extend['alipayPublicKey'],
  1221. ];
  1222. Yii::info(json_encode($config) . ' aplipay config');
  1223. $alipayWap = Yii::getAlias("@vendor/alipayWap");
  1224. require_once($alipayWap . '/wappay/service/AlipayTradeService.php');
  1225. require_once($alipayWap . '/wappay/buildermodel/AlipayTradeWapPayContentBuilder.php');
  1226. $totalFee = $order['realPrice'];
  1227. $out_trade_no = $orderSn;//商户订单号,商户网站订单系统中唯一订单号,必填
  1228. $subject = '购买商品';//订单名称,必填
  1229. $total_amount = $totalFee;//付款金额,必填
  1230. $body = '';//商品描述,可空
  1231. $timeout_express = "1m";//超时时间
  1232. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  1233. $passBackParams = 'capitalType=' . $capitalType . '&couponId=' . $couponId . '&sjId=' . $sjId;//将流水类型、优惠卷传过去
  1234. $passBackParams = urlencode($passBackParams);
  1235. $payRequestBuilder = new \AlipayTradeWapPayContentBuilder();
  1236. $payRequestBuilder->setBody($body);
  1237. $payRequestBuilder->setSubject($subject);
  1238. $payRequestBuilder->setOutTradeNo($out_trade_no);
  1239. $payRequestBuilder->setTotalAmount($total_amount);
  1240. $payRequestBuilder->setTimeExpress($timeout_express);
  1241. //在异步通知时将该参数原样返回
  1242. $payRequestBuilder->setPassbackParams($passBackParams);
  1243. //同步通知
  1244. $returnUrl = Yii::$app->params['mallDomain'] . "/#/pages/callback/success?account={$sjId}&shopId={$shopId}&orderSn={$orderSn}&totalPrice={$totalFee}&pageStatus=3&payDiscountPrice=0&payDiscountType=0";
  1245. //异步通知
  1246. $notifyUrl = Yii::$app->params['mallHost'] . "/notice/ali-callback";
  1247. $payResponse = new \AlipayTradeService($config);
  1248. $result = $payResponse->wapPay($payRequestBuilder, $returnUrl, $notifyUrl);
  1249. //直接将支付宝的html返回给前端
  1250. echo $result;
  1251. } elseif ($payWay == 2) {
  1252. //余额支付
  1253. util::fail('暂不支持');
  1254. } else {
  1255. util::fail('无效的支付方式');
  1256. }
  1257. }
  1258. //订单评价
  1259. public function actionComment()
  1260. {
  1261. $post = Yii::$app->request->post();
  1262. $id = $post['id'];
  1263. $order = OrderService::getById($id);
  1264. OrderService::valid($order, $this->mainId);
  1265. if ($order['grade'] > 0) {
  1266. util::fail('您已经评过了');
  1267. }
  1268. OrderService::comment($post);
  1269. util::complete('提交成功');
  1270. }
  1271. //订单详情,不需要登陆可以查看,要有盐,给跑腿上查看订单信息用的
  1272. public function actionInfo()
  1273. {
  1274. $get = Yii::$app->request->get();
  1275. $id = $get['id'] ?? 0;
  1276. $salt = $get['salt'] ?? '';
  1277. $detail = OrderClass::getFullInfo($id);
  1278. if (empty($detail)) {
  1279. util::fail('没有找到订单');
  1280. }
  1281. if (empty($detail['salt'])) {
  1282. util::fail('没有找到订单信息');
  1283. }
  1284. if (empty($salt)) {
  1285. util::fail('请求参数错误呢');
  1286. }
  1287. if ($detail['salt'] != $salt) {
  1288. util::fail('不是你的订单');
  1289. }
  1290. util::success($detail);
  1291. }
  1292. //订单详情
  1293. public function actionDetail()
  1294. {
  1295. $id = Yii::$app->request->get('id', 0);
  1296. $detail = OrderClass::getFullInfo($id);
  1297. OrderService::valid($detail, $this->mainId);
  1298. $forwardMap = [];
  1299. if ($detail['forward'] == 1) {
  1300. //当前单如果已经是红冲订单,则取出其对应的原单
  1301. $map = OrderForwardClass::getByCondition(['shOrderId' => $id], true);
  1302. if (!empty($map)) {
  1303. $originOrderId = $map->orderId ?? 0;
  1304. $forwardMap['orderId'] = $originOrderId;
  1305. }
  1306. }
  1307. $detail['forwardMap'] = $forwardMap;
  1308. $shOrderMap = [];
  1309. if ($detail['hasForward'] == 1) {
  1310. $shOrderMap = OrderForwardClass::getAllByCondition(['orderId' => $id], null, '*');
  1311. }
  1312. $detail['shOrderMap'] = $shOrderMap;
  1313. $main = $this->main;
  1314. //是否走红冲订单模式判断 ssh
  1315. $ret = OrderClass::ifShPay($detail, $main, 0);
  1316. $shAddPay = $ret['shAddPay'];
  1317. $shAddPayReason = $ret['shAddPayReason'];
  1318. $detail['shAddPay'] = $shAddPay;
  1319. $detail['shAddPayReason'] = $shAddPayReason;
  1320. util::success($detail);
  1321. }
  1322. public function actionList()
  1323. {
  1324. $get = Yii::$app->request->get();
  1325. $searchText = $get['searchText'] ?? '';
  1326. $shopId = $this->shopId ?? 0;
  1327. if (empty($shopId)) {
  1328. //没有登录不显示数据
  1329. util::success(['list' => [], 'moreData' => 0, 'shop' => [], 'totalNum' => 0, 'totalPage' => 0]);
  1330. }
  1331. $where = [];
  1332. $where['shopId'] = $shopId;
  1333. if (!empty($get['customId'])) {
  1334. $where['customId'] = $get['customId'];
  1335. }
  1336. if (!empty($get['ids'])) {
  1337. $stringIds = $get['ids'];
  1338. $newIds = explode(',', $stringIds);
  1339. $where['id'] = ['in', $newIds];
  1340. }
  1341. $status = $get['status'] ?? 0;
  1342. if (!empty($status)) {
  1343. $where['status'] = $get['status'];
  1344. }
  1345. $debt = $get['debt'] ?? -1;
  1346. if ($debt > -1) {
  1347. $where['debt'] = $debt;
  1348. }
  1349. if (!empty($get['shopAdminId'])) {
  1350. $where['shopAdminId'] = $get['shopAdminId'];
  1351. }
  1352. // 按搜索词自动识别:纯数字查货号,否则查姓名
  1353. if (!empty($searchText)) {
  1354. $this->appendOrderListSearchWhere($where, $searchText);
  1355. }
  1356. if (isset($get['repeat']) && $get['repeat'] > -1) {
  1357. $where['repeat'] = $get['repeat'];
  1358. }
  1359. if (!empty($get['searchTime'])) {
  1360. $startTime = $get['startTime'] ?? '';
  1361. $endTime = $get['endTime'] ?? '';
  1362. $period = dateUtil::formatTime($get['searchTime'], $startTime, $endTime);
  1363. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  1364. }
  1365. $list = OrderService::getOrderList($where);
  1366. $list['shop'] = $this->shop->attributes ?? [];
  1367. util::success($list);
  1368. }
  1369. //订单归类 ssh 2019.12.17
  1370. public function actionClassify()
  1371. {
  1372. $post = Yii::$app->request->post();
  1373. $id = $post['id'] ?? 0;
  1374. $order = OrderService::getById($id);
  1375. OrderService::valid($order, $this->mainId);
  1376. $categoryId = $post['categoryId'];
  1377. $usageId = $post['usageId'];
  1378. OrderService::classify($id, $categoryId, $usageId);
  1379. util::complete();
  1380. }
  1381. //更新配送单 ssh 2019.12.17
  1382. public function actionUpdateSheet()
  1383. {
  1384. $post = Yii::$app->request->post();
  1385. $id = $post['id'] ?? 0;
  1386. unset($post['id']);
  1387. $order = OrderService::getById($id);
  1388. OrderService::valid($order, $this->mainId);
  1389. OrderService::updateSheet($order, $post);
  1390. util::complete('提交成功');
  1391. }
  1392. //商家收款与发货 ssh 2019.12.18
  1393. public function actionGathering()
  1394. {
  1395. $post = Yii::$app->request->post();
  1396. $price = isset($post['price']) && is_numeric($post['price']) ? $post['price'] : 0;
  1397. $payWay = isset($post['payWay']) && is_numeric($post['payWay']) ? $post['payWay'] : 0;
  1398. $userId = $post['userId'] ?? 0;
  1399. $userInfo = UserService::getById($userId);
  1400. if (empty($userInfo) || $userInfo['sjId'] != $this->sjId) {
  1401. util::fail('您选择的客户无效');
  1402. }
  1403. if ($price <= 0) {
  1404. util::fail('请输入金额');
  1405. }
  1406. $post['prePrice'] = $price;
  1407. $post['actPrice'] = $price;
  1408. $post['payWay'] = $payWay;
  1409. $post['sourceType'] = 1;
  1410. $post['userId'] = $userId;
  1411. $post['goodsNum'] = 1;
  1412. $post['orderName'] = '商品';
  1413. $shopId = MerchantService::getDefaultShopId($this->sj);
  1414. $post['shopId'] = $shopId;
  1415. $order = OrderService::addOrder($post);
  1416. $id = $order['id'];
  1417. $orderSn = $order['orderSn'];
  1418. //流水类型列表
  1419. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  1420. $callbackParams = [];
  1421. switch ($payWay) {
  1422. case 0:
  1423. xhPayToolService::wxPay($callbackParams, $orderSn, $price, $capitalType, 0);
  1424. break;
  1425. case 1:
  1426. xhPayToolService::alipay($callbackParams, $orderSn, $price, $capitalType, 0, []);
  1427. break;
  1428. case 2:
  1429. xhPayToolService::balancePay($callbackParams, $orderSn, $price, $capitalType, 0);
  1430. break;
  1431. default:
  1432. util::fail('无效支付方式');
  1433. }
  1434. util::success($order);
  1435. }
  1436. //免发货管理 ssh 2020.1.6
  1437. public function actionWithoutSend()
  1438. {
  1439. $id = Yii::$app->request->get('id');
  1440. $order = OrderService::getById($id);
  1441. OrderService::valid($order, $this->mainId);
  1442. //配送流程变更
  1443. $currentFlow = OrderSendClass::withoutSend($order);
  1444. util::success(['currentFlow' => $currentFlow]);
  1445. }
  1446. //修改价格 ssh 2020.1.6
  1447. public function actionUpdatePrice()
  1448. {
  1449. $id = Yii::$app->request->get('id');
  1450. $price = Yii::$app->request->get('price', 1);
  1451. $order = OrderService::getById($id);
  1452. OrderService::valid($order, $this->mainId);
  1453. if (isset($order['modPrice']) && $order['modPrice'] == 0) {
  1454. util::fail('已发起支付,不能修改价格');
  1455. }
  1456. OrderService::updateById($id, ['actPrice' => $price]);
  1457. util::complete('修改成功');
  1458. }
  1459. //配送单 ssh 2020.2.29
  1460. public function actionGetDeliverDetail()
  1461. {
  1462. $id = Yii::$app->request->get('id', 0);
  1463. $order = OrderService::getById($id);
  1464. OrderService::valid($order, $this->mainId);
  1465. $reachDate = isset($order['reachDate']) && !empty($order['reachDate']) ? $order['reachDate'] : '';
  1466. $reachPeriodId = $order['reachPeriod'];
  1467. $reachPeriodArr = [0 => '上午', 1 => '下午', 2 => '晚上'];
  1468. $reachPeriod = isset($reachPeriodArr[$reachPeriodId]) ? $reachPeriodArr[$reachPeriodId] : '';
  1469. $bookName = isset($order['bookName']) ? $order['bookName'] : '';
  1470. $bookMobile = isset($order['bookMobile']) ? $order['bookMobile'] : '';
  1471. if (isset($order['anonymity']) && $order['anonymity'] == 1) {
  1472. $bookName = '--';
  1473. $bookMobile = '--';
  1474. }
  1475. $data = [
  1476. 'reachDate' => $reachDate . ' ' . $reachPeriod,
  1477. 'orderSn' => $order['orderSn'],
  1478. 'receiveUserName' => $order['receiveUserName'],
  1479. 'receiveMobile' => $order['receiveMobile'],
  1480. 'fullAddress' => $order['fullAddress'] . "(" . $order['showAddress'] . ")",
  1481. 'cardInfo' => $order['cardInfo'],
  1482. 'bookMobile' => $bookMobile,
  1483. 'bookName' => $bookName,
  1484. 'remark' => $order['remark'],
  1485. 'sendNum' => $order['sendNum'],
  1486. 'telephone' => 18030142050,
  1487. 'printTime' => '',
  1488. 'img' => '',
  1489. ];
  1490. util::success($data);
  1491. }
  1492. //运费计算 lqh 2021.4.12 暂反回固定
  1493. public function actionFreight()
  1494. {
  1495. util::success(['sedCost' => 10]);
  1496. }
  1497. /**
  1498. * 订单列表搜索条件:纯数字按货号精确匹配,否则按客户姓名模糊匹配
  1499. * @param array $where 查询条件(引用传递)
  1500. * @param string $searchText 搜索关键词
  1501. */
  1502. private function appendOrderListSearchWhere(&$where, $searchText)
  1503. {
  1504. $searchText = trim((string)$searchText);
  1505. if ($searchText === '') {
  1506. return;
  1507. }
  1508. if (preg_match('/^\d+$/', $searchText)) {
  1509. $where['sendNum'] = $searchText;
  1510. return;
  1511. }
  1512. $where['customName'] = ['like', $searchText];
  1513. }
  1514. }