OrderController.php 67 KB

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