PurchaseController.php 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660
  1. <?php
  2. namespace hd\controllers;
  3. use biz\admin\classes\AdminClass;
  4. use biz\common\classes\GhsNotifyClass;
  5. use biz\ghs\classes\GhsClass;
  6. use biz\shop\classes\ShopClass;
  7. use biz\shop\classes\ShopExtClass;
  8. use bizGhs\custom\classes\AccountMoneyClass;
  9. use bizGhs\custom\classes\CustomClass;
  10. use bizGhs\express\classes\GhsDeliveryOrderClass;
  11. use bizGhs\order\classes\OrderClass;
  12. use bizHd\cg\classes\CgMergeSnClass;
  13. use bizHd\purchase\classes\PurchaseClass;
  14. use bizHd\purchase\classes\PurchaseItemClass;
  15. use bizHd\purchase\services\PurchaseService;
  16. use bizGhs\product\classes\ProductClass;
  17. use bizHd\wx\classes\WxOpenClass;
  18. use common\components\dateUtil;
  19. use common\components\delivery\util\DeliveryQuoteUtil;
  20. use common\components\dict;
  21. use common\components\imgUtil;
  22. use common\components\noticeUtil;
  23. use common\components\orderSn;
  24. use Yii;
  25. use common\components\util;
  26. use bizGhs\order\services\OrderService;
  27. use common\components\lakala\Lakala;
  28. use common\components\qrCodeUtil;
  29. use common\components\push;
  30. class PurchaseController extends BaseController
  31. {
  32. public $guestAccess = ['detail', 'ali-pay', 'get-ali-pay-code', 'wx-pay', 'merge-order-list','debt-list'];
  33. //取消采购单 ssh 20250710
  34. public function actionCancel()
  35. {
  36. $get = Yii::$app->request->get();
  37. $id = $get['id'] ?? '';
  38. $info = PurchaseClass::getById($id, true);
  39. if (empty($info)) {
  40. util::fail('没有找到采购单');
  41. }
  42. if (!isset($info->mainId) || $info->mainId != $this->mainId) {
  43. util::fail('访问错误');
  44. }
  45. if ($info->status == 5) {
  46. util::fail('已取消');
  47. }
  48. if ($info->status != 1) {
  49. util::fail('不能取消');
  50. }
  51. PurchaseService::expire($info);
  52. util::complete('已取消');
  53. }
  54. //获取支付宝付款码 ssh 20240713
  55. public function actionGetAliPayCode()
  56. {
  57. $get = Yii::$app->request->get();
  58. $orderSn = $get['orderSn'] ?? '';
  59. $info = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
  60. if (empty($info)) {
  61. util::fail('没有找到采购单');
  62. }
  63. if (!isset($info->mainId) || $info->mainId != $this->mainId) {
  64. //重要,这个不能限制,因为开单分享给客户付款的,要显示支付宝二维码,限制了会不显示!!!!!! shish 20260326
  65. //util::fail('无法访问!');
  66. }
  67. if (getenv('YII_ENV') == 'production') {
  68. $url = "https://mall.huahb.cn/#/admin/cg/alipay?orderSn={$orderSn}";
  69. } else {
  70. $url = "https://mall.huaml.com/#/admin/cg/alipay?orderSn={$orderSn}";
  71. }
  72. $unique = "order_ali_pay_" . $orderSn;
  73. $imgUrl = qrCodeUtil::generateRechargeQrCode($url, $unique);
  74. $imageUrl = imgUtil::groupImg($imgUrl);
  75. util::success(['imgUrl' => $imageUrl]);
  76. }
  77. //确认收货 ssh 20231119
  78. public function actionConfirmTake()
  79. {
  80. $get = Yii::$app->request->get();
  81. $id = $get['id'] ?? 0;
  82. $info = PurchaseClass::getById($id, true);
  83. if (empty($info)) {
  84. util::fail('没有找到采购单');
  85. }
  86. if (isset($info->mainId) == false || $info->mainId != $this->mainId) {
  87. util::fail('无法访问!!');
  88. }
  89. PurchaseClass::confirmTake($info);
  90. util::complete('确认成功');
  91. }
  92. public function actionGetFullInfo()
  93. {
  94. $get = Yii::$app->request->get();
  95. $id = $get['id'] ?? 0;
  96. $info = PurchaseClass::getById($id);
  97. if (empty($info)) {
  98. util::fail('没有找到采购单');
  99. }
  100. if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) {
  101. util::fail('无法访问。。。');
  102. }
  103. $orderSn = $info['orderSn'] ?? '';
  104. $ghsId = $info['ghsId'] ?? 0;
  105. $info['ghsShopId'] = 0;
  106. if (!empty($ghsId)) {
  107. $ghs = GhsClass::getById($ghsId, true);
  108. $info['ghsShopId'] = $ghs->shopId ?? 0;
  109. }
  110. $list = PurchaseItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
  111. if (!empty($list)) {
  112. foreach ($list as $key => $item) {
  113. $shortCover = $item['cover'] ?? '';
  114. $cover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
  115. $bigCover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  116. $list[$key]['cover'] = $cover;
  117. $list[$key]['bigCover'] = $bigCover;
  118. $list[$key]['shortCover'] = $shortCover;
  119. }
  120. }
  121. $info['product'] = $list;
  122. util::success($info);
  123. }
  124. //虚拟供货商的采购 ssh 20230308
  125. public function actionAddVirtualCg()
  126. {
  127. $post = Yii::$app->request->post();
  128. $ghsId = $post['ghsId'] ?? 0;
  129. $payMode = $post['payMode'] ?? 0;
  130. $payWay = $post['payWay'] ?? 0;
  131. $ghsInfo = GhsClass::getById($ghsId);
  132. if (empty($ghsInfo)) {
  133. util::fail('没有找到供货商');
  134. }
  135. if (isset($ghsInfo['mainId']) && !empty($ghsInfo['mainId']) && $ghsInfo['mainId'] == $ghsInfo['ownMainId']) {
  136. util::fail('不能向自己的店买花');
  137. }
  138. $connection = Yii::$app->db;
  139. $transaction = $connection->beginTransaction();
  140. $transactionFinished = false;
  141. register_shutdown_function(function () use (&$transactionFinished, $transaction) {
  142. if ($transactionFinished) {
  143. return;
  144. }
  145. ProductClass::rollbackLimitBuySnapshot();
  146. if ($transaction->isActive) {
  147. $transaction->rollBack();
  148. }
  149. });
  150. try {
  151. $post['book'] = $post['book'] ?? 0;
  152. $post['sjId'] = $this->sjId;
  153. $post['shopId'] = $this->shopId;
  154. $post['shopAdminId'] = $this->shopAdminId;
  155. $post['ghsId'] = $ghsId;
  156. $post['ghsName'] = $ghsInfo['name'] ?? '';
  157. $post['ghsMobile'] = $ghsInfo['mobile'] ?? '';
  158. $post['ghsAvatar'] = $ghsInfo['avatar'] ?? '';
  159. $post['ghsFullAddress'] = $ghsInfo['fullAddress'] ?? '';
  160. $customId = $ghsInfo['customId'] ?? 0;
  161. $post['customId'] = $customId;
  162. $shopAdmin = $this->shopAdmin ?? null;
  163. $name = $shopAdmin->name ?? '';
  164. $post['shopAdminName'] = $name;
  165. $post['mainId'] = $this->mainId;
  166. $product = $post['product'] ?? '';
  167. $productList = json_decode($product, true);
  168. //判断product数据是不是同个供货商的
  169. $ids = array_unique(array_filter(array_column($productList, 'productId')));
  170. $productInfoList = ProductClass::getByIds($ids, null, 'id');
  171. if (!empty($productInfoList)) {
  172. foreach ($productInfoList as $currentInfo) {
  173. if (isset($currentInfo['mainId']) == false || $currentInfo['mainId'] != $this->mainId) {
  174. util::fail('只能选择同一家的商品哦');
  175. }
  176. }
  177. if (count($productInfoList) != count($ids)) {
  178. util::fail('存在无效商品');
  179. }
  180. } else {
  181. util::fail('花材不存在');
  182. }
  183. //供货商预订单最低公斤数要求和每公斤服务费
  184. $ghsInfo['kiloFee'] = 0;
  185. $ghsInfo['miniKilo'] = 0;
  186. $post['product'] = $productList;
  187. $packCost = 0;
  188. $post['packCost'] = $packCost;
  189. $post['sendCost'] = isset($post['sendCost']) && $post['sendCost'] > 0 ? $post['sendCost'] : 0;
  190. $respond = PurchaseService::createPurchase($post, $ghsInfo);
  191. if ($payMode == 0) {
  192. //欠款
  193. PurchaseService::debt($respond);
  194. } else {
  195. //线下支付
  196. PurchaseService::payAfter($respond, $payWay);
  197. $saleId = $respond->saleId ?? 0;
  198. $order = OrderClass::getById($saleId, true);
  199. if (empty($order)) {
  200. util::fail('没有找到订单');
  201. }
  202. OrderService::payAfter($order, $payWay, true);
  203. }
  204. $transaction->commit();
  205. $transactionFinished = true;
  206. ProductClass::clearLimitBuyRollbackSnapshot();
  207. util::success($respond);
  208. } catch (\Throwable $e) {
  209. if ($transaction->isActive) {
  210. $transaction->rollBack();
  211. }
  212. ProductClass::rollbackLimitBuySnapshot();
  213. $transactionFinished = true;
  214. util::fail();
  215. }
  216. }
  217. // 批发商的限购花材信息
  218. public function actionLimitBuyInfo()
  219. {
  220. $post = Yii::$app->request->post();
  221. $ghsId = $post['ghsId'] ?? 0;
  222. $list = $post['list'] ?? [];
  223. if (empty($ghsId)) {
  224. util::fail('缺少供货商');
  225. }
  226. if (empty($list) || !is_array($list)) {
  227. util::fail('请选择花材');
  228. }
  229. $ghsInfo = GhsClass::getById($ghsId);
  230. if (empty($ghsInfo)) {
  231. util::fail('没有找到供货商');
  232. }
  233. $customId = $ghsInfo['customId'] ?? 0;
  234. if (empty($customId)) {
  235. util::fail('没有找到客户');
  236. }
  237. $respond = ProductClass::getLimitBuyInfoByList($list, $customId);
  238. util::success($respond);
  239. }
  240. //生成采购单 ssh 2021.1.17
  241. public function actionCreateOrder()
  242. {
  243. $post = Yii::$app->request->post();
  244. $version = $post['version'] ?? 0;
  245. $direct = $post['direct'] ?? 0;
  246. //避免重复提交
  247. $adminId = $this->adminId;
  248. util::checkRepeatCommit($adminId, 3);
  249. //多颜色数据整理
  250. $colorItem = $post['xj'] ?? [];
  251. $newXj = [];
  252. if (!empty($colorItem)) {
  253. $colorData = json_decode($colorItem, true);
  254. if (!empty($colorData) && is_array($colorData)) {
  255. foreach ($colorData as $colorInfo) {
  256. $ptItemId = $colorInfo['ptItemId'] ?? 0;
  257. $colorList = $colorInfo['list'] ?? [];
  258. if (!empty($colorList)) {
  259. foreach ($colorList as $colorItemKey => $colorItem) {
  260. $newXj[$ptItemId][] = $colorItem;
  261. }
  262. }
  263. }
  264. }
  265. }
  266. $post['xj'] = $newXj;
  267. $ghsId = $post['ghsId'] ?? 0;
  268. //供货商
  269. $ghsInfo = GhsClass::getById($ghsId);
  270. if (empty($ghsInfo)) {
  271. util::fail('没有找到供货商');
  272. }
  273. $ghsShopId = $ghsInfo['shopId'] ?? 0;
  274. if (!empty($ghsInfo['mainId']) && $ghsInfo['mainId'] == $ghsInfo['ownMainId']) {
  275. util::fail('不能跟自己的店买花');
  276. }
  277. $connection = Yii::$app->db;
  278. $transaction = $connection->beginTransaction();
  279. $transactionFinished = false;
  280. register_shutdown_function(function () use (&$transactionFinished, $transaction) {
  281. if ($transactionFinished) {
  282. return;
  283. }
  284. ProductClass::rollbackLimitBuySnapshot();
  285. if ($transaction->isActive) {
  286. $transaction->rollBack();
  287. }
  288. });
  289. try {
  290. $post['book'] = $post['book'] ?? 0;
  291. $post['sjId'] = $this->sjId;
  292. $post['shopId'] = $this->shopId;
  293. $post['shopAdminId'] = $this->shopAdminId;
  294. $post['ghsId'] = $ghsId;
  295. $post['ghsName'] = $ghsInfo['name'] ?? '';
  296. $post['ghsMobile'] = $ghsInfo['mobile'] ?? '';
  297. $post['ghsAvatar'] = $ghsInfo['avatar'] ?? '';
  298. $post['ghsFullAddress'] = $ghsInfo['fullAddress'] ?? '';
  299. $customId = $ghsInfo['customId'] ?? 0;
  300. $custom = CustomClass::getById($customId, true);
  301. if (empty($custom)) {
  302. util::fail('用户信息缺失');
  303. }
  304. $post['customId'] = $customId;
  305. $shopAdmin = $this->shopAdmin ?? null;
  306. $name = $shopAdmin->name ?? '';
  307. $post['shopAdminName'] = $name;
  308. $post['mainId'] = $this->mainId;
  309. $product = $post['product'] ?? '';
  310. $productList = json_decode($product, true);
  311. //判断product数据是不是同个供货商的
  312. $ghsShopInfo = ShopClass::getById($ghsShopId, true);
  313. $ghsMainId = $ghsShopInfo->mainId ?? 0;
  314. $isOpen = ShopClass::isOpen($ghsShopInfo);
  315. $book = $post['book'] ?? 0;
  316. if ($isOpen == 0 && $book == 0) {
  317. util::fail('本店已休息,请选择其它门店');
  318. }
  319. if (isset($post['transType']) && $post['transType'] == 4) {
  320. if (isset($ghsShopInfo->pfLevel) && $ghsShopInfo->pfLevel == 1) {
  321. $notSameCity = PurchaseClass::notSameCity($this->shop, $ghsShopInfo);
  322. if (!$notSameCity) {
  323. util::fail('距离太远,不能选择同城配送');
  324. }
  325. }
  326. }
  327. if ($book == 1) {
  328. $sendTimeWant = isset($post['sendTimeWant']) && !empty($post['sendTimeWant']) ? $post['sendTimeWant'] : date("Y-m-d");
  329. $future = date("Y-m-d", strtotime('+2 day'));
  330. if (strtotime($sendTimeWant) < strtotime($future)) {
  331. //util::fail('请选择时间');
  332. }
  333. $nowTime = strtotime(date("Y-m-d"));
  334. if (strtotime($sendTimeWant) < $nowTime) {
  335. util::fail('不能选择过去时间');
  336. }
  337. }
  338. //收集客户要下单的花材数量
  339. $orderNum = [];
  340. $productCount = 0;
  341. foreach ($productList as $key => $product) {
  342. $bigNum = $product['bigNum'] ?? 0;
  343. $smallNum = $product['smallNum'] ?? 0;
  344. $pName = $product['name'] ?? '';
  345. if ($smallNum > 0) {
  346. util::fail($pName . '不能选小单位');
  347. }
  348. $productId = $product['productId'] ?? 0;
  349. $orderNum[$productId] = ['num' => $bigNum];
  350. $productCount += $bigNum;
  351. }
  352. $lackList = [];
  353. $changeList = [];
  354. $ids = array_unique(array_filter(array_column($productList, 'productId')));
  355. $productInfoList = ProductClass::getByIds($ids, null, 'id');
  356. if (!empty($productInfoList)) {
  357. $presellData = [];
  358. $nowTime = strtotime(date("Y-m-d"));
  359. foreach ($productInfoList as $currentInfo) {
  360. if (!isset($currentInfo['mainId']) || $currentInfo['mainId'] != $ghsMainId) {
  361. util::fail('只能选择同一家的商品哦');
  362. }
  363. $currentName = $currentInfo['name'] ?? '';
  364. if (isset($currentInfo['frontHide']) && $currentInfo['frontHide'] == 1) {
  365. //珑松珠海店,隐藏的商品,分享出去了也要能下单。644 是测试账号的mainId
  366. if (isset($currentInfo['mainId']) && in_array($currentInfo['mainId'], [14116, 644])) {
  367. //无操作
  368. } else {
  369. util::fail($currentName . ' 没有库存,请删除');
  370. }
  371. }
  372. $presell = $currentInfo['presell'] ?? 0;
  373. $presellData[] = $presell;
  374. if ($presell == 1) {
  375. if ($book == 1) {
  376. util::fail('预订时不能选择预售花材');
  377. } else {
  378. if (empty($post['sendTimeWant'])) {
  379. util::fail('请选择配送日期');
  380. }
  381. $sendTimeWant = $post['sendTimeWant'];
  382. if (strtotime($sendTimeWant) < $nowTime) {
  383. util::fail('不能选择过去时间');
  384. }
  385. $hasDateStr = $currentInfo['presellDate'] ?? [];
  386. $hasDate = explode(',', trim($hasDateStr));
  387. if (empty($hasDate)) {
  388. util::fail('预售日期有问题,请提醒门店');
  389. }
  390. if (!in_array(strtotime($sendTimeWant), $hasDate)) {
  391. util::fail("有预售花材在{$sendTimeWant}没到货");
  392. }
  393. $post['presell'] = 1;
  394. }
  395. }
  396. if ($version >= 10) {
  397. $stock = $currentInfo['stock'] ?? 0;
  398. $stock = floatval($stock);
  399. //会有0.5扎和2.5扎问题,所以要转成整数,不然会出严重问题 ssh 20250503
  400. $stock = intval($stock);
  401. $productId = $currentInfo['id'] ?? 0;
  402. $productName = $currentInfo['name'] ?? '';
  403. $num = $orderNum[$productId] && $orderNum[$productId]['num'] ? $orderNum[$productId]['num'] : 0;
  404. $num = floatval($num);
  405. if ($num > $stock) {
  406. $lackList[] = ['name' => $productName, 'stock' => $stock];
  407. $changeList[$productId] = $stock;
  408. }
  409. }
  410. }
  411. if (count($productInfoList) != count($ids)) {
  412. util::fail('存在无效商品');
  413. }
  414. $presellData = array_unique($presellData);
  415. if (count($presellData) > 1) {
  416. util::fail('预售和非预售花材不能一起下单');
  417. }
  418. if ($version >= 10) {
  419. if ($direct == 1) {
  420. //直接更换库存并提交
  421. $allNoStock = true;
  422. foreach ($productList as $pKey => $pVal) {
  423. $productId = $pVal['productId'] ?? 0;
  424. if (isset($changeList[$productId])) {
  425. $changeStock = $changeList[$productId];
  426. $productList[$pKey]['bigNum'] = $changeStock;
  427. }
  428. if ($productList[$pKey]['bigNum'] > 0) {
  429. $allNoStock = false;
  430. }
  431. if ($productList[$pKey]['bigNum'] <= 0) {
  432. unset($productList[$pKey]);
  433. }
  434. }
  435. if ($allNoStock) {
  436. util::fail('全部没库存了');
  437. }
  438. } else {
  439. //前台提示库存不足
  440. if (!empty($lackList)) {
  441. util::success(['lackList' => $lackList, 'hasLackError' => 1]);
  442. }
  443. }
  444. }
  445. // 已经有了 -- 在 replaceItem()
  446. // foreach ($productList as $itemData) {
  447. // $productId = $itemData['productId'] ?? 0;
  448. // $product = $productInfoList[$productId] ?? [];
  449. // if (empty($product)) {
  450. // util::fail('有商品信息没有找到');
  451. // }
  452. // $bigNum = $itemData['bigNum'] ?? 0;
  453. // if (($product['limitBuy'] ?? 0) > 0) {
  454. // $product['productId'] = $productId;
  455. // ProductClass::handleLimitBuy($product, $customId, floatval($bigNum));
  456. // }
  457. // }
  458. } else {
  459. util::fail('花材不存在');
  460. }
  461. //供货商预订单最低公斤数要求和每公斤服务费
  462. $ghsInfo['kiloFee'] = $ghsShopInfo->kiloFee ?? 0;
  463. $ghsInfo['miniKilo'] = $ghsShopInfo->miniKilo ?? 0;
  464. $post['product'] = $productList;
  465. $sendType = $post['sendType'] ?? 0;
  466. $transType = $post['transType'] ?? 0;
  467. if ($sendType == dict::getDict('sendType', 'thirdSend')) {
  468. $shopExt = ShopExtClass::getByCondition(['shopId' => $ghsShopId], true, null, 'id,shopId,thirdSend,hcMap,hcFreeKm');
  469. if ($shopExt->thirdSend == 1) {
  470. util::fail('本店暂不能使用跑腿哦');
  471. }
  472. }
  473. if (isset($ghsShopInfo->pfLevel) && $ghsShopInfo->pfLevel == 1) {
  474. //昆明发货包装费和运费的计算
  475. $totalWeight = 0;
  476. $totalItemNum = 0;
  477. foreach ($productList as $itemData) {
  478. $bigNum = $itemData['bigNum'] ?? 0;
  479. $thisWeight = $itemData['weight'] ?? 0;
  480. $currentWeight = bcmul($thisWeight, $bigNum, 2);
  481. $totalWeight = bcadd($currentWeight, $totalWeight, 2);
  482. $totalItemNum = bcadd($totalItemNum, $bigNum, 2);
  483. }
  484. $totalItemNum = floatval($totalItemNum);
  485. $kmPackCost = PurchaseClass::getKmPackCost($ghsMainId);
  486. $packCost = 0;
  487. if (!empty($kmPackCost)) {
  488. foreach ($kmPackCost as $itemPack) {
  489. $kiloNum = $itemPack['num'] ?? 0;
  490. if ($kiloNum >= $totalWeight) {
  491. $packCost = $itemPack['amount'] ?? 0;
  492. break;
  493. }
  494. }
  495. if (isset($ghsInfo['mainId']) && $ghsInfo['mainId'] == 14499) {
  496. noticeUtil::push("总重量" . $totalWeight, '15280215347');
  497. }
  498. }
  499. if (isset($ghsInfo['mainId']) && $ghsInfo['mainId'] == 14499) {
  500. noticeUtil::push("走的pfLevel=1", '15280215347');
  501. }
  502. //同城配送和到店自取免打包费
  503. if ($transType == 4 || $transType == 5) {
  504. $packCost = 0;
  505. if (isset($ghsInfo['mainId']) && $ghsInfo['mainId'] == 14499) {
  506. noticeUtil::push("没有计算打包费原因:transType = 4 =5", '15280215347');
  507. }
  508. }
  509. //如果已经算过一次打包费和运费了,则不再费了
  510. $needAdd = \bizHd\shop\classes\ShopClass::needAddPackCost($ghsShopInfo, $customId);
  511. if (!$needAdd) {
  512. $packCost = 0;
  513. if (isset($ghsInfo['mainId']) && $ghsInfo['mainId'] == 14499) {
  514. noticeUtil::push("没有计算打包费原因:已经算过一次了", '15280215347');
  515. }
  516. }
  517. $post['packCost'] = $packCost;
  518. $transCost = dict::getDict('transCost', null, null, $ghsShopInfo->mainId);
  519. $sendCost = 0;
  520. if (!empty($transCost)) {
  521. foreach ($transCost as $trans) {
  522. $sign = $trans['sign'] ?? 0;
  523. if ($sign == $transType) {
  524. if ($sign == 2) {
  525. //冷链物流
  526. $llOption = $trans['option'] ?? [];
  527. if (!empty($llOption)) {
  528. $largeInfo = end($llOption);
  529. $largeNum = $largeInfo['num'] ?? 0;
  530. $largeAmount = $largeInfo['amount'] ?? 0;
  531. $bs = intval($totalItemNum / $largeNum);
  532. if ($bs > 0) {
  533. $addSendCost = bcmul($bs, $largeAmount, 2);
  534. $sendCost = bcadd($sendCost, $addSendCost, 2);
  535. $subNum = bcmul($bs, $largeNum, 2);
  536. $subNum = floatval($subNum);
  537. $totalItemNum = bcsub($totalItemNum, $subNum, 2);
  538. $totalItemNum = floatval($totalItemNum);
  539. }
  540. foreach ($llOption as $miniItem) {
  541. if ($miniItem['num'] >= $totalItemNum) {
  542. $sendCost = bcadd($sendCost, $miniItem['amount'], 2);
  543. break;
  544. }
  545. }
  546. }
  547. } else {
  548. //其它物流
  549. $perKiloCost = $trans['perKiloCost'] ?? 0;
  550. $sendCost = bcmul($perKiloCost, $totalWeight, 3);
  551. $sendCost = round($sendCost, 2);
  552. }
  553. }
  554. }
  555. }
  556. //如果已经算过一次打包费和运费了,则不再费了
  557. $needAdd = \bizHd\shop\classes\ShopClass::needAddPackCost($ghsShopInfo, $customId);
  558. if ($needAdd == false) {
  559. $sendCost = 0;
  560. }
  561. $post['sendCost'] = $sendCost;
  562. //标记为昆明到地方订单
  563. $post['localOrder'] = 1;
  564. } else {
  565. //同城发货包装费和运费的计算
  566. $sendCost = 0;
  567. $sendDistance = 0;
  568. //特别注意,这边取供货商的shop信息
  569. $mapSet = ShopClass::hasIntraCity($ghsShopInfo);
  570. $openIntraCity = $mapSet['openIntraCity'] ?? 0;
  571. if ($sendType == dict::getDict('sendType', 'thirdSend')) {
  572. if ($openIntraCity == 2) {
  573. util::fail('不能使用跑腿');
  574. }
  575. if ($openIntraCity == 1) {
  576. // 生成随机订单号,不要跟原来的混起来,跑腿-销售单-
  577. $prefix = 'PT-XSD-' . $this->mainId . '-';
  578. $orderSn = $prefix . round(microtime(true) * 1000);
  579. // 使用 DeliveryQuoteUtil 获取配送报价
  580. try {
  581. if (empty($post['deliveryPlatform'])) {
  582. util::fail('请选择跑腿');
  583. }
  584. $quoteResult = DeliveryQuoteUtil::getDeliveryQuote([
  585. 'productList' => $productList,
  586. 'deliveryPlatform' => $post['deliveryPlatform'],
  587. 'deliveryBracketContent' => $post['deliveryBracketContent'], // 平台多报价识别id
  588. 'ghsInfo' => $ghsInfo,
  589. 'custom' => $custom,
  590. 'order' => [
  591. 'orderSn' => $orderSn,
  592. 'goodsType' => 1, //商品类型:0花束 1花材
  593. 'itemTotalAmount' => $post['itemTotalAmount'] ?? 0,
  594. 'remark' => $post['remark'] ?? '',
  595. ],
  596. 'mainId' => $this->mainId,
  597. 'productCount' => $productCount,
  598. ]);
  599. $sendCost = $quoteResult['sendCost'];
  600. $sendDistance = $quoteResult['sendDistance'];
  601. } catch (\Exception $e) {
  602. util::fail($e->getMessage());
  603. }
  604. }
  605. }
  606. $post['sendCost'] = $sendCost;
  607. $post['sendDistance'] = $sendDistance;
  608. //出车、发快递、发物流可以算包装费
  609. $packCost = 0;
  610. if (isset($ghsInfo['mainId']) && $ghsInfo['mainId'] == 14499) {
  611. noticeUtil::push("走的pfLevel=0", '15280215347');
  612. }
  613. $itemTotalAmount = $post['itemTotalAmount'] ?? 0;
  614. unset($post['itemTotalAmount']);
  615. if ($sendType == dict::getDict('sendType', 'express')) {
  616. $needAdd = \bizHd\shop\classes\ShopClass::needAddPackCost($ghsShopInfo, $customId, $itemTotalAmount);
  617. if ($needAdd) {
  618. $packCost = $ghsShopInfo->packCost ?? 0;
  619. }
  620. }
  621. $post['packCost'] = $packCost;
  622. }
  623. if (isset($ghsInfo['mainId']) && $ghsInfo['mainId'] == 14499) {
  624. noticeUtil::push("包装费:" . $packCost, '15280215347');
  625. }
  626. $respond = PurchaseService::createPurchase($post, $ghsInfo);
  627. if ($sendType == 0) {
  628. if (getenv('YII_ENV') == 'production') {
  629. //杭州斗南鲜花批发部,满500,10公里内免费配送,满1000,20公里免费配送
  630. if ($ghsShopId == 4608) {
  631. if ($respond->actPrice < 500) {
  632. $transaction->rollBack();
  633. util::fail('满500元支持免费配送');
  634. }
  635. }
  636. //叶上花,满500元市区免费配送
  637. if ($ghsShopId == 4804) {
  638. if ($respond->actPrice < 500) {
  639. $transaction->rollBack();
  640. util::fail('满500元支持免费配送');
  641. }
  642. }
  643. //花悠星 国恋 勇记 万丽 陆丰暂时不支持免费配送
  644. if ($ghsShopId == 7687 || $ghsShopId == 7831 || $ghsShopId == 7778 || $ghsShopId == 12003 || $ghsShopId == 38128) {
  645. util::fail('暂不支持送货上门,请选其它配送方式!');
  646. }
  647. //广州鑫源花卉,选择送货上门必须选必选商品
  648. if ($ghsShopId == 12439) {
  649. $hasMust = array_intersect($ids, [3446945, 3446970, 3446973, 3446979, 3446995, 3447010, 3447023, 3459983, 4333184, 4317745, 1585738]);
  650. if (empty($hasMust)) {
  651. util::fail('请返回选择 必选商品');
  652. }
  653. }
  654. //三明易批花
  655. if ($ghsShopId == 82200) {
  656. if ($respond->actPrice < 100 || $respond->bigNum < 15) {
  657. $hasMust = array_intersect($ids, [4283478]);
  658. if (empty($hasMust)) {
  659. util::fail('没满100元且15扎,请返回选运费');
  660. }
  661. }
  662. // 按当天计时,把 sendTimeWant 要限制在两天的时间范围之内
  663. $future = date("Y-m-d", strtotime('+2 day'));
  664. if (strtotime($respond->sendTimeWant) > strtotime($future)) {
  665. util::fail('配送日期只能选最近二天');
  666. }
  667. }
  668. if ($ghsShopId == 77703) {
  669. //天天鲜花思明店,暂时关闭送货上门
  670. if ($respond->sendType == 0) {
  671. //util::fail('节日暂停送货上门,请选到店自取');
  672. }
  673. }
  674. if ($ghsShopId == 86726) {
  675. //藏花林
  676. if ($respond->transType != 4 && $respond->transType != 5) {
  677. util::fail('请选同城配送或到店自取');
  678. }
  679. }
  680. } else {
  681. //好运鲜花批发,选择送货上门必须选必选商品
  682. // if ($ghsShopId == 36523) {
  683. // if ($respond->transType != 4 && $respond->transType != 5) {
  684. // util::fail('请选同城配送或到店自取');
  685. // }
  686. // }
  687. // if ($ghsShopId == 36523) {
  688. // if ($respond->actPrice < 50 || $respond->bigNum < 10) {
  689. // $hasMust = array_intersect($ids, [85295]);
  690. // if (empty($hasMust)) {
  691. // util::fail('没满50元且满10扎,请运费必选商品');
  692. // }
  693. // }
  694. // // 按当天计时,把 sendTimeWant 要限制在两天的时间范围之内
  695. // $future = date("Y-m-d", strtotime('+2 day'));
  696. // if (strtotime($respond->sendTimeWant) > strtotime($future)) {
  697. // util::fail('配送日期只能选最近二天');
  698. // }
  699. // }
  700. }
  701. if (isset($ghsInfo['home'])) {
  702. if ($ghsInfo['home'] == 0) {
  703. util::fail('暂不支持送货上门,请选其它配送方式');
  704. }
  705. $homeAmount = $ghsInfo['homeAmount'] ? floatval($ghsInfo['homeAmount']) : 0;
  706. $homeNum = $ghsInfo['homeNum'] ? floatval($ghsInfo['homeNum']) : 0;
  707. if ($homeAmount > 0 && $homeAmount > $respond->actPrice) {
  708. util::fail("满{$homeAmount}元 可送货上门");
  709. }
  710. if ($homeNum > 0 && $homeNum > $respond->bigNum) {
  711. util::fail("满{$homeNum}扎 可送货上门");
  712. }
  713. }
  714. }
  715. if ($sendType == 2) {
  716. //温州易批花,跑腿,不满100,要选10元的补运费商品
  717. if ($ghsShopId == 91115) {
  718. if ($respond->actPrice < 100) {
  719. $transaction->rollBack();
  720. $hasMust = array_intersect($ids, [4449812, 4449811]);
  721. if (empty($hasMust)) {
  722. util::fail('不满100,必选商品 补运费10元');
  723. }
  724. }
  725. }
  726. }
  727. if ($sendType == 4) {
  728. //温州易批花,快递,不满100,要选10元的补运费商品
  729. if ($ghsShopId == 91115) {
  730. if ($respond->actPrice < 100) {
  731. $transaction->rollBack();
  732. $hasMust = array_intersect($ids, [4449812, 4449811]);
  733. if (empty($hasMust)) {
  734. util::fail('不满100,必选商品 补运费10元');
  735. }
  736. }
  737. }
  738. }
  739. if ($sendType == 3) {
  740. //温州易批花,物流,不满200,要选10元的补运费商品
  741. if ($ghsShopId == 91115) {
  742. if ($respond->actPrice < 200) {
  743. $transaction->rollBack();
  744. $hasMust = array_intersect($ids, [4449812, 4449811]);
  745. if (empty($hasMust)) {
  746. util::fail('不满200,必选商品 补运费10元');
  747. }
  748. }
  749. }
  750. }
  751. $transaction->commit();
  752. $transactionFinished = true;
  753. ProductClass::clearLimitBuyRollbackSnapshot();
  754. util::success($respond);
  755. } catch (\Exception $e) {
  756. if ($transaction->isActive) {
  757. $transaction->rollBack();
  758. }
  759. ProductClass::rollbackLimitBuySnapshot();
  760. $transactionFinished = true;
  761. Yii::error($e->getMessage());
  762. util::fail();
  763. }
  764. }
  765. //赊账 ssh 2021.1.24
  766. public function actionDebtPay()
  767. {
  768. $get = Yii::$app->request->get();
  769. $orderSn = $get['orderSn'] ?? 0;
  770. $info = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
  771. PurchaseService::valid($info, $this->shopId);
  772. //解决重复和并发提交
  773. $cacheKey = 'hd_debt_pay_' . $orderSn;
  774. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  775. if (!empty($has)) {
  776. util::fail('请稍等...');
  777. }
  778. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 5, 'has']);
  779. if ($info->status == 5) {
  780. util::fail('订单已取消');
  781. }
  782. if ($info->status != 1) {
  783. util::fail('订单不是待付款状态');
  784. }
  785. if ($info->book == 1) {
  786. util::fail('预售不能记欠款');
  787. }
  788. $ghsId = $info->ghsId;
  789. $ghs = GhsClass::getGhsInfo($ghsId);
  790. $customId = $ghs['customId'] ?? 0;
  791. $custom = CustomClass::getCustom($customId);
  792. if (empty($custom)) {
  793. util::fail('没有找到客户');
  794. }
  795. if (isset($custom['debt']) == false || $custom['debt'] == CustomClass::IS_DEBT_NO) {
  796. util::fail('请先申请赊账权限');
  797. }
  798. if (getenv('YII_ENV') == 'production') {
  799. //源花汇不允许客户自己下欠款单
  800. if ($ghs['mainId'] == 10536) {
  801. util::fail('暂未开通');
  802. }
  803. }
  804. $connection = Yii::$app->db;
  805. $transaction = $connection->beginTransaction();
  806. try {
  807. //延期支付
  808. PurchaseService::debt($info);
  809. $transaction->commit();
  810. if (isset($info->localOrder) && $info->localOrder == 1) {
  811. if ($info->transType != 5 && $info->transType != 4) {
  812. //昆明发货,客户算了一次打包费和运费,第二次就不再算了
  813. $current = date("Y_m_d");
  814. $key = 'ghs_custom_today_has_get_pack_cost_' . $current . '_' . $customId;
  815. Yii::$app->redis->executeCommand('SETEX', [$key, 86400, '1']);
  816. }
  817. } else {
  818. if (isset($info->sendType) && $info->sendType == 4) {
  819. //标记当天已收一次包装费,岭南批发市场用的功能
  820. $current = date("Y_m_d");
  821. $key = 'ghs_custom_today_has_get_pack_cost_' . $current . '_' . $customId;
  822. Yii::$app->redis->executeCommand('SETEX', [$key, 86400, '1']);
  823. }
  824. }
  825. //不是预订单,并且供货商不是源花汇、小明鲜花、淄博花超、云漫梦金鹏、海翔,则订单直接完成掉。是预订单,则确认发货时直接完成掉。有多个地方要修改,请搜索关键词zjFinish
  826. $cg = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
  827. if (!empty($cg)) {
  828. if (isset($cg->book) && $cg->book == 0) {
  829. $ghsShopId = $ghs['shopId'] ?? 0;
  830. $ext = ShopExtClass::getByCondition(['shopId' => $ghsShopId], true, null, 'id,shopId,orderFlow');
  831. if ($ext->orderFlow == 0) {
  832. PurchaseClass::confirmTake($cg);
  833. }
  834. }
  835. }
  836. //app新订单通知
  837. $saleId = $info->saleId ?? 0;
  838. $order = OrderClass::getById($saleId, true);
  839. if (!empty($order)) {
  840. $shopId = $order->shopId ?? 0;
  841. $shop = ShopClass::getById($shopId, true);
  842. if (!empty($shop)) {
  843. //通知供货商
  844. GhsNotifyClass::newOrderNotify($saleId);
  845. }
  846. //订单生成时唤起在线打印
  847. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  848. //有几个地方要同步去修改
  849. if (getenv('YII_ENV') == 'production') {
  850. //源花汇、盛丰不自动打小票,关键词mall_order_no_auto_print
  851. $mallOrderNoPrint = [10536, 44282, 26374];
  852. } else {
  853. $mallOrderNoPrint = [];
  854. }
  855. if (in_array($order->mainId, $mallOrderNoPrint)) {
  856. } else {
  857. OrderClass::onlinePrint($order);
  858. $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  859. if (isset($ext->printSn) && !empty($ext->printSn)) {
  860. $order->printNum += 1;
  861. $order->save();
  862. }
  863. //花镜 打二次小票,有多处要修改搜索关键词tow_print
  864. if (in_array($order->mainId, [76796])) {
  865. OrderClass::onlinePrint($order);
  866. $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  867. if (isset($ext->printSn) && !empty($ext->printSn)) {
  868. $order->printNum += 1;
  869. $order->save();
  870. }
  871. }
  872. }
  873. }
  874. //付款成功之后呼叫跑腿,关键词 pay_after_call_pt,多处要同步修改
  875. GhsDeliveryOrderClass::payAfter($order);
  876. //更新最后下单时间
  877. $customId = $order->customId ?? 0;
  878. $custom = CustomClass::getById($customId, true);
  879. $date = date("Y-m-d H:i:s");
  880. if (!empty($custom)) {
  881. $custom->recentExpend = $date;
  882. $custom->save();
  883. }
  884. $ghsId = $order->ghsId ?? 0;
  885. $ghs = GhsClass::getById($ghsId, true);
  886. if (!empty($ghs)) {
  887. $ghs->recentExpend = $date;
  888. $ghs->save();
  889. }
  890. }
  891. } catch (\Exception $e) {
  892. $transaction->rollBack();
  893. util::fail('支付失败');
  894. }
  895. util::success($info->attributes);
  896. }
  897. /**
  898. * 采购待支付页:客户 xhGhsCustom 净余额支付(并发重试 + 行锁)。
  899. */
  900. public function actionCustomBalancePay()
  901. {
  902. $post = Yii::$app->request->post();
  903. $orderSn = $post['orderSn'] ?? '';
  904. if (empty($orderSn)) {
  905. util::fail('订单号无效');
  906. }
  907. $cacheKey = 'hd_custom_balance_pay_' . $orderSn;
  908. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  909. if (!empty($has)) {
  910. util::fail('请稍等...');
  911. }
  912. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 8, 'has']);
  913. $info = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
  914. if (empty($info)) {
  915. util::fail('没有找到采购单');
  916. }
  917. PurchaseService::valid($info, $this->shopId);
  918. $deadline = $info->deadline ?? '';
  919. if (!empty($deadline) && time() > strtotime($deadline)) {
  920. util::fail('订单已失效了哦');
  921. }
  922. $ghsId = intval($info->ghsId ?? 0);
  923. $ghs = GhsClass::getGhsInfo($ghsId);
  924. try {
  925. $result = util::runWithDbConcurrencyRetry(function () use ($orderSn) {
  926. $connection = Yii::$app->db;
  927. $transaction = $connection->beginTransaction();
  928. try {
  929. $purchase = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
  930. $respond = PurchaseService::payByGhsCustomBalance($purchase);
  931. $transaction->commit();
  932. return $respond;
  933. } catch (\Exception $exception) {
  934. if ($transaction->isActive) {
  935. $transaction->rollBack();
  936. }
  937. throw $exception;
  938. }
  939. });
  940. $info = $result['purchase'];
  941. $order = $result['saleOrder'] ?? null;
  942. if (!empty($order)) {
  943. if (isset($info->book) && $info->book == 0 && !empty($ghs)) {
  944. $ghsShopId = $ghs['shopId'] ?? 0;
  945. $ext = ShopExtClass::getByCondition(['shopId' => $ghsShopId], true, null, 'id,shopId,orderFlow');
  946. if (!empty($ext) && intval($ext->orderFlow ?? 0) === 0) {
  947. $cg = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
  948. if (!empty($cg)) {
  949. PurchaseClass::confirmTake($cg);
  950. }
  951. }
  952. }
  953. $shopId = $order->shopId ?? 0;
  954. $shop = ShopClass::getById($shopId, true);
  955. if (!empty($shop)) {
  956. GhsNotifyClass::newOrderNotify($order->id ?? 0);
  957. }
  958. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  959. OrderClass::onlinePrint($order);
  960. }
  961. GhsDeliveryOrderClass::payAfter($order);
  962. $customId = $order->customId ?? 0;
  963. $custom = CustomClass::getById($customId, true);
  964. $date = date('Y-m-d H:i:s');
  965. if (!empty($custom)) {
  966. $custom->recentExpend = $date;
  967. $custom->save();
  968. }
  969. $orderGhsId = $order->ghsId ?? 0;
  970. $orderGhs = GhsClass::getById($orderGhsId, true);
  971. if (!empty($orderGhs)) {
  972. $orderGhs->recentExpend = $date;
  973. $orderGhs->save();
  974. }
  975. }
  976. util::success($info->attributes);
  977. } catch (\Exception $e) {
  978. Yii::info('客户余额支付失败:' . $e->getMessage());
  979. util::fail($e->getMessage() ?: '支付失败');
  980. }
  981. }
  982. //余额支付 ssh 2021.1.24
  983. public function actionBalancePay()
  984. {
  985. $shopAdmin = $this->shopAdmin;
  986. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  987. util::fail('超管才能操作');
  988. }
  989. $get = Yii::$app->request->get();
  990. $orderSn = $get['orderSn'] ?? 0;
  991. $password = $get['password'] ?? '';
  992. // 重新获取,不加密的用户数据
  993. $admin = AdminClass::getById($this->adminId, true);
  994. if (password_verify($password, $admin->payPassword) == false) {
  995. util::fail('密码错误');
  996. }
  997. $info = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
  998. if (empty($info)) {
  999. util::fail('没有找到采购单');
  1000. }
  1001. if ($info->status == 5) {
  1002. util::fail('订单已取消');
  1003. }
  1004. if ($info->status != 1) {
  1005. util::fail('订单不是待付款状态');
  1006. }
  1007. PurchaseService::valid($info, $this->shopId);
  1008. $connection = Yii::$app->db;
  1009. $transaction = $connection->beginTransaction();
  1010. try {
  1011. //余额支付
  1012. purchaseService::balancePay($info);
  1013. $transaction->commit();
  1014. } catch (\Exception $e) {
  1015. $transaction->rollBack();
  1016. util::fail('支付失败');
  1017. }
  1018. util::success($info->attributes);
  1019. }
  1020. //采购记录 ssh 2021.1.24
  1021. public function actionList()
  1022. {
  1023. $get = Yii::$app->request->get();
  1024. $where = ['shopId' => $this->shopId];
  1025. $searchTime = $get['searchTime'] ?? '';
  1026. if (!empty($searchTime)) {
  1027. $startTime = $get['startTime'] ?? '';
  1028. $endTime = $get['endTime'] ?? '';
  1029. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  1030. $where['payTime'] = ['between', [$period['startTime'], $period['endTime']]];
  1031. }
  1032. $ghsId = $get['ghsId'] ?? 0;
  1033. if (!empty($ghsId)) {
  1034. $where['ghsId'] = $ghsId;
  1035. }
  1036. $status = $get['status'] ?? 0;
  1037. if (!empty($status)) {
  1038. $where['status'] = $status;
  1039. }
  1040. $respond = PurchaseService::getPurchaseList($where);
  1041. $respond['shop'] = $this->shop->attributes;
  1042. util::success($respond);
  1043. }
  1044. //获取合并采购单列表 ssh 20260519
  1045. public function actionMergeOrderList()
  1046. {
  1047. Yii::$app->params['pageSize'] = 9999;
  1048. $get = Yii::$app->request->get();
  1049. $mergeId = $get['mergeId'] ?? 0;
  1050. if (empty($mergeId)) {
  1051. util::fail('请选择采购单');
  1052. }
  1053. $mergeSn = CgMergeSnClass::getById($mergeId, true);
  1054. if (empty($mergeSn)) {
  1055. util::fail('请选择合并采购单');
  1056. }
  1057. $salt = $get['salt'] ?? '';
  1058. if (!empty($salt)) {
  1059. if (empty($mergeSn->salt) || $mergeSn->salt != $salt) {
  1060. util::fail('此单无法查看哦');
  1061. }
  1062. } else {
  1063. if (empty($this->shopId)) {
  1064. util::fail('暂时不能查看');
  1065. }
  1066. if ($mergeSn->mainId != $this->mainId) {
  1067. util::fail('此单无法查看哈');
  1068. }
  1069. }
  1070. $ghsId = $mergeSn->ghsId ?? 0;
  1071. $where = [
  1072. 'ghsId' => $ghsId,
  1073. 'mergeId' => $mergeId,
  1074. ];
  1075. $respond = PurchaseService::getPurchaseList($where);
  1076. $totalPrice = 0;
  1077. if (!empty($respond['list'])) {
  1078. foreach ($respond['list'] as $one) {
  1079. $actPrice = $one['actPrice'] ?? 0;
  1080. $totalPrice = bcadd($totalPrice, $actPrice, 2);
  1081. }
  1082. }
  1083. $totalPrice = floatval($totalPrice);
  1084. $respond['totalPrice'] = $totalPrice;
  1085. $respond['shop'] = !empty($this->shop) ? $this->shop->attributes : [];
  1086. util::success($respond);
  1087. }
  1088. //采购详情 ssh 2021.01.25
  1089. public function actionDetail()
  1090. {
  1091. $get = Yii::$app->request->get();
  1092. $id = $get['id'] ?? 0;
  1093. $info = PurchaseService::getInfo($id, true, true);
  1094. if (empty($info)) {
  1095. util::fail('没有找到采购单');
  1096. }
  1097. $salt = $get['salt'] ?? '';
  1098. if (!empty($salt)) {
  1099. if (!isset($info['salt']) || $info['salt'] != $salt) {
  1100. util::fail('无效采购单呢!');
  1101. }
  1102. } else {
  1103. if (!isset($info['mainId']) || $info['mainId'] != $this->mainId) {
  1104. util::fail('采购单不能访问');
  1105. }
  1106. }
  1107. $customId = $info['customId'] ?? 0;
  1108. $custom = CustomClass::getById($customId);
  1109. $customName = $custom['name'] ?? '';
  1110. $customMobile = $custom['mobile'] ?? '';
  1111. $info['customName'] = $customName;
  1112. $info['customMobile'] = $customMobile;
  1113. $hasDebtPay = $custom['debt'] ?? 0;
  1114. $book = $info['book'] ?? 0;
  1115. $presell = $info['presell'] ?? 0;
  1116. //预售不能记欠款
  1117. if ($book == 1) {
  1118. $hasDebtPay = 0;
  1119. }
  1120. if ($presell == 1) {
  1121. $hasDebtPay = 0;
  1122. }
  1123. $shop = $this->shop;
  1124. $info['pfShopId'] = $shop->pfShopId ?? 0;
  1125. $info['hasDebtPay'] = $hasDebtPay;
  1126. // 待支付页展示 xhGhsCustom 净余额(正数=可支付余额),不再使用 main.balance
  1127. $info['balance'] = 0;
  1128. $info['customNetBalance'] = '0.00';
  1129. $info['showBalancePay'] = 0;
  1130. $info['ghsSalt'] = '';
  1131. $ghsId = intval($info['ghsId'] ?? 0);
  1132. if ($ghsId > 0) {
  1133. $ghsRow = GhsClass::getById($ghsId, true);
  1134. if (!empty($ghsRow)) {
  1135. $info['ghsSalt'] = $ghsRow->salt ?? '';
  1136. $ghsCustomId = intval($ghsRow->customId ?? 0);
  1137. if ($ghsCustomId > 0) {
  1138. $ghsCustom = CustomClass::getById($ghsCustomId, true);
  1139. if (!empty($ghsCustom)) {
  1140. $net = AccountMoneyClass::getNetBalanceFromRow($ghsCustom);
  1141. $info['customNetBalance'] = $net;
  1142. if (bccomp($net, '0', 2) > 0) {
  1143. $info['balance'] = floatval($net);
  1144. $info['showBalancePay'] = 1;
  1145. }
  1146. }
  1147. }
  1148. }
  1149. }
  1150. $getPayType = dict::getDict('getPayType');
  1151. $info['getPayType'] = $getPayType;
  1152. //获取售后条件
  1153. $ghsId = $info['ghsId'] ?? 0;
  1154. $ghsInfo = GhsClass::getById($ghsId, true);
  1155. if (empty($ghsInfo)) {
  1156. util::fail('没有找到供货商');
  1157. }
  1158. $info['afterSale'] = $ghsInfo->afterSale ?? 1;
  1159. //重要,客户看到的电话修改成门店的联系电话
  1160. $ghsShopId = $ghsInfo->shopId ?? 0;
  1161. $ghsShopInfo = ShopClass::getById($ghsShopId, true);
  1162. $info['ghsMobile'] = $ghsShopInfo->telephone ?? '';
  1163. $info['ghsMobile2'] = $ghsShopInfo->telephone2 ?? '';
  1164. $info['hasRenew'] = 1;
  1165. //如果是快捷开单,则不需要显示累计待结,因为商家经常把快捷开单的订单发给客户结账
  1166. $showForPay = 1;
  1167. if ($ghsShopInfo->skCustomId == $info['customId']) {
  1168. $showForPay = 0;
  1169. }
  1170. $info['showForPay'] = $showForPay;
  1171. util::success($info);
  1172. }
  1173. //可用的支付方式 ssh 2021.1.25
  1174. public function actionPayWay()
  1175. {
  1176. $button = [
  1177. ['type' => 'wxPay', 'show' => 1, 'disable' => 1],
  1178. ['type' => 'debtPay', 'show' => 1, 'disable' => 0],
  1179. ['type' => 'balancePay', 'show' => 1, 'disable' => 0],
  1180. ];
  1181. util::success(['button' => $button]);
  1182. }
  1183. //待结款明细 ssh 2021.1.26
  1184. public function actionDebtList()
  1185. {
  1186. $get = Yii::$app->request->get();
  1187. $id = $get['id'] ?? 0;
  1188. $salt = $get['salt'] ?? '';
  1189. $info = GhsClass::getGhsInfo($id);
  1190. if (!empty($salt)) {
  1191. if (!isset($info['salt']) || $info['salt'] != $salt) {
  1192. util::fail('供货商出错了');
  1193. }
  1194. } else {
  1195. if (!isset($info['ownShopId']) || $info['ownShopId'] != $this->shopId) {
  1196. util::fail('错误的供货商.');
  1197. }
  1198. }
  1199. $where = ['ghsId' => $id, 'debt' => PurchaseClass::DEBT_YES];
  1200. $searchTime = $get['searchTime'] ?? '';
  1201. if (!empty($searchTime)) {
  1202. $startTime = $get['startTime'] ?? '';
  1203. $endTime = $get['endTime'] ?? '';
  1204. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  1205. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  1206. }
  1207. $respond = PurchaseService::getDebtList($where);
  1208. util::success($respond);
  1209. }
  1210. //支付宝支付 ssh 2021.4.11
  1211. public function actionAliPay()
  1212. {
  1213. ini_set('date.timezone', 'Asia/Shanghai');
  1214. $post = Yii::$app->request->post();
  1215. //默认是支付宝支付
  1216. $payWay = $post['payWay'] ?? 1;
  1217. $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
  1218. $order = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
  1219. if (empty($order)) {
  1220. util::fail('订单号无效');
  1221. }
  1222. if ($order->status == 5) {
  1223. util::fail('订单已取消');
  1224. }
  1225. if ($order->status != 1) {
  1226. util::fail('订单不是待付款状态');
  1227. }
  1228. $deadline = $order->deadline;
  1229. $current = time();
  1230. if (($current + 50) > strtotime($deadline)) {
  1231. util::fail('订单已失效,请重新下单');
  1232. }
  1233. $ghsId = $order->ghsId ?? 0;
  1234. $ghs = GhsClass::getById($ghsId, true);
  1235. if (empty($ghs)) {
  1236. util::fail('没有供货商信息');
  1237. }
  1238. $ghsShopId = $ghs->shopId ?? 0;
  1239. $ghsShop = ShopClass::getById($ghsShopId, true);
  1240. if (empty($ghsShop)) {
  1241. util::fail('没有供货商门店信息');
  1242. }
  1243. if (isset($ghsShop->lklSjNo) && empty($ghsShop->lklSjNo)) {
  1244. util::fail('商家支付功能未开通');
  1245. }
  1246. //避免重复提交
  1247. util::checkRepeatCommit($orderSn, 8);
  1248. //已经唤起过支付了,根据拉卡拉的规则,需要生成新的订单号
  1249. if ($order->changePrice == 2) {
  1250. $oldOrderSn = $orderSn;
  1251. //老单号需要关单,否则有付款成功的风险,老单号关闭成功了,才能生成新单号
  1252. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  1253. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  1254. $params = [
  1255. 'appid' => 'OP00002119',
  1256. 'serial_no' => '018b08cfddbd',
  1257. 'merchant_no' => $ghsShop->lklSjNo,
  1258. 'term_no' => $ghsShop->lklScanTermNo,
  1259. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  1260. 'lklCertificatePath' => $lklCertificatePath,
  1261. ];
  1262. $laResource = new Lakala($params);
  1263. $closeParams = [
  1264. 'orderSn' => $oldOrderSn,
  1265. ];
  1266. $response = $laResource->cashClose($closeParams);
  1267. if (isset($response['code']) == false || $response['code'] != '000000') {
  1268. $msg = $response['msg'] ?? '';
  1269. $code = $response['code'] ?? 0;
  1270. if (!in_array($code, ['000091'])) {
  1271. noticeUtil::push('注意花店买花更换单号:' . $oldOrderSn . ',关单没有成功(收银台-支付宝),' . $msg, '15280215347');
  1272. }
  1273. }
  1274. $shopId = $order->shopId ?? 0;
  1275. $mainId = $order->mainId ?? 0;
  1276. $customId = $order->customId ?? 0;
  1277. $ghsId = $order->ghsId ?? 0;
  1278. $snData = ['shopId' => $shopId, 'mainId' => $mainId, 'customId' => $customId, 'ghsId' => $ghsId];
  1279. $newOrderSn = orderSn::getPurchaseSn($snData);
  1280. $orderSn = $newOrderSn;
  1281. $order->orderSn = $newOrderSn;
  1282. $order->save();
  1283. PurchaseItemClass::updateByCondition(['orderSn' => $oldOrderSn], ['orderSn' => $newOrderSn]);
  1284. }
  1285. $order->changePrice = 2;
  1286. $order->save();
  1287. $ghsShopName = $ghsShop->shopName ?? '';
  1288. //要带上哪个店的,这样才知道客户下的单是哪个店的,客户很多有多家店
  1289. $name = $ghsShopName . " 花材 " . $orderSn;
  1290. $totalFee = $order->realPrice;
  1291. $purchaseCapital = dict::getDict('capitalType', 'xhPurchase', 'id');
  1292. $ghsId = $order->ghsId ?? 0;
  1293. $ghs = GhsClass::getById($ghsId, true);
  1294. if (empty($ghs)) {
  1295. util::fail('没有供货商信息');
  1296. }
  1297. $ghsShopId = $ghs->shopId ?? 0;
  1298. $ghsShop = ShopClass::getById($ghsShopId, true);
  1299. if (empty($ghsShop)) {
  1300. util::fail('没有供货商门店信息');
  1301. }
  1302. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  1303. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  1304. $params = [
  1305. 'appid' => 'OP00002119',
  1306. 'serial_no' => '018b08cfddbd',
  1307. 'merchant_no' => $ghsShop->lklSjNo,
  1308. 'term_no' => $ghsShop->lklB2BTermNo,
  1309. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  1310. 'lklCertificatePath' => $lklCertificatePath,
  1311. ];
  1312. $laResource = new Lakala($params);
  1313. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/cash-pay-callback";
  1314. $wxParams = [
  1315. 'orderSn' => $orderSn,
  1316. 'amount' => $totalFee,
  1317. 'capitalType' => $purchaseCapital,
  1318. 'notifyUrl' => $notifyUrl,
  1319. 'subject' => $name,
  1320. 'payWay' => $payWay,
  1321. ];
  1322. $response = $laResource->cashierPay($wxParams);
  1323. if (isset($response['code']) == false || $response['code'] != '000000') {
  1324. $errMsg = $response['msg'] ?? '';
  1325. noticeUtil::push('编号AA90:' . $errMsg, '15280215347');
  1326. util::fail('发起支付失败');
  1327. }
  1328. $counter_url = $response['resp_data']['counter_url'] ? $response['resp_data']['counter_url'] : '';
  1329. $hasRenew = $ghsShop->hasRenew ?? 0;
  1330. $new = [
  1331. 'payUrl' => $counter_url,
  1332. 'orderSn' => $orderSn,
  1333. 'hasRenew' => 1,
  1334. ];
  1335. util::success($new);
  1336. }
  1337. //微信支付 ssh 2021.4.11
  1338. public function actionWxPay()
  1339. {
  1340. ini_set('date.timezone', 'Asia/Shanghai');
  1341. $post = Yii::$app->request->post();
  1342. $couponId = $post['couponId'] ?? 0;
  1343. $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
  1344. $order = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
  1345. if (empty($order)) {
  1346. util::fail('订单号无效');
  1347. }
  1348. if ($order->status == 5) {
  1349. util::fail('订单已取消');
  1350. }
  1351. if ($order->status != 1) {
  1352. util::fail('订单不是待付款状态');
  1353. }
  1354. $deadline = $order->deadline;
  1355. $current = time();
  1356. if (($current + 50) > strtotime($deadline)) {
  1357. util::fail('订单已失效,请重新下单');
  1358. }
  1359. //避免重复提交
  1360. util::checkRepeatCommit($orderSn, 8);
  1361. $ghsId = $order->ghsId ?? 0;
  1362. $ghs = GhsClass::getById($ghsId, true);
  1363. if (empty($ghs)) {
  1364. util::fail('没有供货商信息');
  1365. }
  1366. $ghsShopId = $ghs->shopId ?? 0;
  1367. $ghsShop = ShopClass::getById($ghsShopId, true);
  1368. if (empty($ghsShop)) {
  1369. util::fail('没有供货商门店信息');
  1370. }
  1371. if (isset($ghsShop->lklSjNo) && empty($ghsShop->lklSjNo)) {
  1372. util::fail('商家支付功能未开通');
  1373. }
  1374. //已经唤起过微信支付了,根据拉卡拉的规则,需要生成新的订单号
  1375. if ($order->changePrice == 2) {
  1376. $oldOrderSn = $orderSn;
  1377. //老单号需要关单,否则有付款成功的风险,老单号关闭成功了,才能生成新单号
  1378. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  1379. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  1380. $params = [
  1381. 'appid' => 'OP00002119',
  1382. 'serial_no' => '018b08cfddbd',
  1383. 'merchant_no' => $ghsShop->lklSjNo,
  1384. 'term_no' => $ghsShop->lklScanTermNo,
  1385. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  1386. 'lklCertificatePath' => $lklCertificatePath,
  1387. ];
  1388. $laResource = new Lakala($params);
  1389. $closeParams = [
  1390. 'orderSn' => $oldOrderSn,
  1391. ];
  1392. $response = $laResource->close($closeParams);
  1393. if (isset($response['code']) == false || $response['code'] != 'BBS00000') {
  1394. $msg = $response['msg'] ?? '';
  1395. $code = $response['code'] ?? 0;
  1396. if (!in_array($code, ['BBS11114'])) {
  1397. noticeUtil::push('重点注意,花店买花更换单号没有成功,单号:' . $oldOrderSn . ',关单没有成功,' . $msg . $code, '15280215347');
  1398. util::fail('出错了,请重新下单');
  1399. }
  1400. }
  1401. $shopId = $order->shopId ?? 0;
  1402. $mainId = $order->mainId ?? 0;
  1403. $customId = $order->customId ?? 0;
  1404. $snData = ['shopId' => $shopId, 'mainId' => $mainId, 'customId' => $customId, 'ghsId' => $ghsId];
  1405. $newOrderSn = orderSn::getPurchaseSn($snData);
  1406. $orderSn = $newOrderSn;
  1407. $order->orderSn = $newOrderSn;
  1408. $order->save();
  1409. PurchaseItemClass::updateByCondition(['orderSn' => $oldOrderSn], ['orderSn' => $newOrderSn]);
  1410. }
  1411. $id = $order->id;
  1412. $order->changePrice = 2;
  1413. $order->save();
  1414. $ghsShopName = $ghsShop->shopName ?? '';
  1415. //要带上哪个店的,这样才知道客户下的单是哪个店的,客户很多有多家店
  1416. $name = $ghsShopName . " 花材 " . $orderSn;
  1417. $totalFee = $order->realPrice;
  1418. $openId = '';
  1419. if (isset($post['currentMiniOpenId']) && !empty($post['currentMiniOpenId'])) {
  1420. $openId = $post['currentMiniOpenId'];
  1421. //noticeUtil::push('花店采购下单时,通过前端获取了openId:' . $openId, '15280215347');
  1422. }
  1423. if (empty($openId)) {
  1424. if (isset($this->admin) && !empty($this->admin)) {
  1425. if (isset($this->admin->miniOpenId) && !empty($this->admin->miniOpenId)) {
  1426. $openId = $this->admin->miniOpenId;
  1427. noticeUtil::push('花店采购下单时,通过数据库获取了openId:' . $openId, '15280215347');
  1428. }
  1429. }
  1430. }
  1431. if (empty($openId)) {
  1432. $currentShopId = $order->shopId ?? 0;
  1433. $currentShop = ShopClass::getById($currentShopId, true);
  1434. $currentShopName = $currentShop->merchantName . ' ' . $currentShop->shopName;
  1435. $currentMobile = $currentShop->mobile ?? '';
  1436. noticeUtil::push("花店采购时,发现没有openId,请跟进是否采购成功。{$currentShopName} {$currentMobile}", '15280215347');
  1437. util::success(['hasError' => 1, 'hasNoMiniOpenId' => 1]);
  1438. }
  1439. $purchaseCapital = dict::getDict('capitalType', 'xhPurchase', 'id');
  1440. //花卉宝代为申请的微信支付
  1441. $merchantExtend = WxOpenClass::getWxInfo();
  1442. if (empty($ghsShop->lklSjNo)) {
  1443. noticeUtil::push('编号31505:单号:' . $orderSn . ' 商家没有开通收款功能:' . $ghsShopName, '15280215347');
  1444. util::fail('商家未开通支付功能');
  1445. }
  1446. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  1447. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  1448. $params = [
  1449. 'appid' => 'OP00002119',
  1450. 'serial_no' => '018b08cfddbd',
  1451. 'merchant_no' => $ghsShop->lklSjNo,
  1452. 'term_no' => $ghsShop->lklScanTermNo,
  1453. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  1454. 'lklCertificatePath' => $lklCertificatePath,
  1455. ];
  1456. $laResource = new Lakala($params);
  1457. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
  1458. $wxParams = [
  1459. 'orderSn' => $orderSn,
  1460. 'amount' => $totalFee,
  1461. 'capitalType' => $purchaseCapital,
  1462. 'notifyUrl' => $notifyUrl,
  1463. 'wxAppId' => $merchantExtend['miniAppId'],
  1464. 'openId' => $openId,
  1465. 'subject' => $name,
  1466. 'couponId' => $couponId,
  1467. ];
  1468. $response = $laResource->driveWxPay($wxParams);
  1469. if (!isset($response['code']) || $response['code'] != 'BBS00000') {
  1470. $errMsg = $response['msg'] ?? '';
  1471. noticeUtil::push('编号129680931:' . $errMsg . ' 单号:' . $orderSn . ' ' . $ghsShopName, '15280215347');
  1472. util::fail('支付失败');
  1473. }
  1474. $newParams = isset($response['resp_data']['acc_resp_fields']) ? $response['resp_data']['acc_resp_fields'] : [];
  1475. $appId = $newParams['app_id'] ?? '';
  1476. $nonceStr = $newParams['nonce_str'] ?? '';
  1477. $paySign = $newParams['pay_sign'] ?? '';
  1478. $package = $newParams['package'] ?? '';
  1479. $signType = $newParams['sign_type'] ?? '';
  1480. $timeStamp = $newParams['time_stamp'] ?? '';
  1481. $new = [
  1482. 'id' => $id,
  1483. 'appId' => $appId,
  1484. 'nonceStr' => $nonceStr,
  1485. 'paySign' => $paySign,
  1486. 'package' => $package,
  1487. 'signType' => $signType,
  1488. 'timeStamp' => $timeStamp,
  1489. 'orderSn' => $orderSn,
  1490. ];
  1491. util::success($new);
  1492. }
  1493. //计算运费 ssh 20221003
  1494. public function actionFreight()
  1495. {
  1496. $get = Yii::$app->request->get();
  1497. $shop = $this->shop;
  1498. $ghsId = $get['ghsId'] ?? 0;
  1499. $ghs = GhsClass::getById($ghsId, true);
  1500. if (empty($ghs)) {
  1501. util::success(['distance' => 0, 'showDistance' => 0, 'fee' => 0]);
  1502. }
  1503. $ghsShopId = $ghs->shopId ?? 0;
  1504. $ghsShop = ShopClass::getById($ghsShopId, true);
  1505. if (empty($ghsShop)) {
  1506. util::success(['distance' => 0, 'showDistance' => 0, 'fee' => 0]);
  1507. }
  1508. $customId = $ghs->customId ?? 0;
  1509. $custom = CustomClass::getById($customId, true);
  1510. if (empty($custom)) {
  1511. util::success(['distance' => 0, 'showDistance' => 0, 'fee' => 0]);
  1512. }
  1513. $weight = $get['weight'] ?? 0;
  1514. if (empty($weight)) {
  1515. util::success(['distance' => 0, 'showDistance' => 0, 'fee' => 0]);
  1516. }
  1517. $respond = PurchaseClass::getDistanceFee($shop, $ghsShop, $weight, $custom);
  1518. util::success($respond);
  1519. }
  1520. //运费计算 lqh 2021.4.12 暂时返回固定值
  1521. public function actionFreight2()
  1522. {
  1523. //lqh 2021.6.25 运费固定返回0
  1524. util::success(['sedCost' => 0]);
  1525. }
  1526. }