OrderController.php 68 KB

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