OrderController.php 68 KB

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