OrderController.php 67 KB

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