OrderController.php 68 KB

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