OrderController.php 68 KB

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