PurchaseController.php 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151
  1. <?php
  2. namespace hd\controllers;
  3. use biz\admin\classes\AdminClass;
  4. use biz\ghs\classes\GhsClass;
  5. use biz\notice\classes\NoticeClass;
  6. use biz\shop\classes\ShopClass;
  7. use biz\shop\classes\ShopExpressClass;
  8. use bizGhs\custom\classes\CustomClass;
  9. use bizGhs\express\services\DadaExpressServices;
  10. use bizGhs\order\classes\OrderClass;
  11. use bizGhs\order\classes\OrderItemClass;
  12. use bizHd\purchase\classes\PurchaseClass;
  13. use bizHd\purchase\classes\PurchaseItemClass;
  14. use bizHd\purchase\services\PurchaseService;
  15. use bizGhs\product\classes\ProductClass;
  16. use bizHd\wx\classes\WxOpenClass;
  17. use common\components\dateUtil;
  18. use common\components\dict;
  19. use common\components\freight;
  20. use common\components\httpUtil;
  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 biz\wx\classes\WxMessageClass;
  27. use bizGhs\order\services\OrderService;
  28. use common\components\lakala\Lakala;
  29. class PurchaseController extends BaseController
  30. {
  31. public $guestAccess = ['detail'];
  32. //确认收货 ssh 20231119
  33. public function actionConfirmTake()
  34. {
  35. $get = Yii::$app->request->get();
  36. $id = $get['id'] ?? 0;
  37. $info = PurchaseClass::getById($id, true);
  38. if (empty($info)) {
  39. util::fail('没有找到采购单');
  40. }
  41. if (isset($info->mainId) == false || $info->mainId != $this->mainId) {
  42. util::fail('无法访问');
  43. }
  44. PurchaseClass::confirmTake($info);
  45. util::complete('确认成功');
  46. }
  47. public function actionGetFullInfo()
  48. {
  49. $get = Yii::$app->request->get();
  50. $id = $get['id'] ?? 0;
  51. $info = PurchaseClass::getById($id);
  52. if (empty($info)) {
  53. util::fail('没有找到采购单');
  54. }
  55. if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) {
  56. util::fail('无法访问');
  57. }
  58. $orderSn = $info['orderSn'] ?? '';
  59. $list = PurchaseItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
  60. if (!empty($list)) {
  61. foreach ($list as $key => $item) {
  62. $shortCover = $item['cover'] ?? '';
  63. $cover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
  64. $bigCover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  65. $list[$key]['cover'] = $cover;
  66. $list[$key]['bigCover'] = $bigCover;
  67. $list[$key]['shortCover'] = $shortCover;
  68. }
  69. }
  70. $info['product'] = $list;
  71. util::success($info);
  72. }
  73. //虚拟供货商的采购 ssh 20230308
  74. public function actionAddVirtualCg()
  75. {
  76. $post = Yii::$app->request->post();
  77. $ghsId = $post['ghsId'] ?? 0;
  78. $payMode = $post['payMode'] ?? 0;
  79. $payWay = $post['payWay'] ?? 0;
  80. $ghsInfo = GhsClass::getById($ghsId);
  81. if (empty($ghsInfo)) {
  82. util::fail('没有找到供货商');
  83. }
  84. if (isset($ghsInfo['mainId']) && !empty($ghsInfo['mainId']) && $ghsInfo['mainId'] == $ghsInfo['ownMainId']) {
  85. util::fail('不能向自己的店买花');
  86. }
  87. $connection = Yii::$app->db;
  88. $transaction = $connection->beginTransaction();
  89. try {
  90. $post['book'] = $post['book'] ?? 0;
  91. $post['sjId'] = $this->sjId;
  92. $post['shopId'] = $this->shopId;
  93. $post['shopAdminId'] = $this->shopAdminId;
  94. $post['ghsId'] = $ghsId;
  95. $post['ghsName'] = $ghsInfo['name'] ?? '';
  96. $post['ghsMobile'] = $ghsInfo['mobile'] ?? '';
  97. $post['ghsAvatar'] = $ghsInfo['avatar'] ?? '';
  98. $post['ghsFullAddress'] = $ghsInfo['fullAddress'] ?? '';
  99. $customId = $ghsInfo['customId'] ?? 0;
  100. $post['customId'] = $customId;
  101. $shopAdmin = $this->shopAdmin ?? null;
  102. $name = $shopAdmin->name ?? '';
  103. $post['shopAdminName'] = $name;
  104. $post['mainId'] = $this->mainId;
  105. $product = $post['product'] ?? '';
  106. $productList = json_decode($product, true);
  107. //判断product数据是不是同个供货商的
  108. $ids = array_unique(array_filter(array_column($productList, 'productId')));
  109. $productInfoList = ProductClass::getByIds($ids, null, 'id');
  110. if (!empty($productInfoList)) {
  111. foreach ($productInfoList as $currentInfo) {
  112. if (isset($currentInfo['mainId']) == false || $currentInfo['mainId'] != $this->mainId) {
  113. util::fail('只能选择同一家的商品哦');
  114. }
  115. }
  116. if (count($productInfoList) != count($ids)) {
  117. util::fail('存在无效商品');
  118. }
  119. } else {
  120. util::fail('花材不存在');
  121. }
  122. //供货商预订单最低公斤数要求和每公斤服务费
  123. $ghsInfo['kiloFee'] = 0;
  124. $ghsInfo['miniKilo'] = 0;
  125. $post['product'] = $productList;
  126. $packCost = 0;
  127. $post['packCost'] = $packCost;
  128. $post['sendCost'] = isset($post['sendCost']) && $post['sendCost'] > 0 ? $post['sendCost'] : 0;
  129. $respond = PurchaseService::createPurchase($post, $ghsInfo);
  130. if ($payMode == 0) {
  131. //欠款
  132. PurchaseService::debt($respond);
  133. } else {
  134. //线下支付
  135. PurchaseService::payAfter($respond, $payWay);
  136. $saleId = $respond->saleId ?? 0;
  137. $order = OrderClass::getById($saleId, true);
  138. if (empty($order)) {
  139. util::fail('没有找到订单');
  140. }
  141. OrderService::payAfter($order, $payWay, true);
  142. }
  143. $transaction->commit();
  144. util::success($respond);
  145. } catch (Exception $e) {
  146. $transaction->rollBack();
  147. util::fail();
  148. }
  149. }
  150. //生成采购单 ssh 2021.1.17
  151. public function actionCreateOrder()
  152. {
  153. $post = Yii::$app->request->post();
  154. //多颜色数据整理
  155. $colorItem = $post['xj'] ?? [];
  156. $newXj = [];
  157. if (!empty($colorItem)) {
  158. $colorData = json_decode($colorItem, true);
  159. if (!empty($colorData) && is_array($colorData)) {
  160. foreach ($colorData as $colorInfo) {
  161. $ptItemId = $colorInfo['ptItemId'] ?? 0;
  162. $colorList = $colorInfo['list'] ?? [];
  163. if (!empty($colorList)) {
  164. foreach ($colorList as $colorItemKey => $colorItem) {
  165. $newXj[$ptItemId][] = $colorItem;
  166. }
  167. }
  168. }
  169. }
  170. }
  171. $post['xj'] = $newXj;
  172. $ghsId = $post['ghsId'] ?? 0;
  173. //供货商
  174. $ghsInfo = GhsClass::getById($ghsId);
  175. if (empty($ghsInfo)) {
  176. util::fail('没有找到供货商');
  177. }
  178. $ghsShopId = $ghsInfo['shopId'] ?? 0;
  179. if (isset($ghsInfo['mainId']) && !empty($ghsInfo['mainId']) && $ghsInfo['mainId'] == $ghsInfo['ownMainId']) {
  180. util::fail('不能跟自己的店买花');
  181. }
  182. $connection = Yii::$app->db;//事务处理
  183. $transaction = $connection->beginTransaction();
  184. try {
  185. $post['book'] = $post['book'] ?? 0;
  186. $post['sjId'] = $this->sjId;
  187. $post['shopId'] = $this->shopId;
  188. $post['shopAdminId'] = $this->shopAdminId;
  189. $post['ghsId'] = $ghsId;
  190. $post['ghsName'] = $ghsInfo['name'] ?? '';
  191. $post['ghsMobile'] = $ghsInfo['mobile'] ?? '';
  192. $post['ghsAvatar'] = $ghsInfo['avatar'] ?? '';
  193. $post['ghsFullAddress'] = $ghsInfo['fullAddress'] ?? '';
  194. $customId = $ghsInfo['customId'] ?? 0;
  195. $post['customId'] = $customId;
  196. $shopAdmin = $this->shopAdmin ?? null;
  197. $name = $shopAdmin->name ?? '';
  198. $post['shopAdminName'] = $name;
  199. $post['mainId'] = $this->mainId;
  200. $product = $post['product'] ?? '';
  201. $productList = json_decode($product, true);
  202. //判断product数据是不是同个供货商的
  203. $ghsShopInfo = ShopClass::getById($ghsShopId, true);
  204. $ghsMainId = $ghsShopInfo->mainId ?? 0;
  205. $isOpen = ShopClass::isOpen($ghsShopInfo);
  206. $book = $post['book'] ?? 0;
  207. if ($isOpen == 0 && $book == 0) {
  208. util::fail('本店已休息,请选择其它门店');
  209. }
  210. if (isset($post['transType']) && $post['transType'] == 4) {
  211. if (isset($ghsShopInfo->pfLevel) && $ghsShopInfo->pfLevel == 1) {
  212. $notSameCity = PurchaseClass::notSameCity($this->shop, $ghsShopInfo);
  213. if ($notSameCity == false) {
  214. util::fail('距离太远,不能选择同城配送');
  215. }
  216. }
  217. }
  218. if ($book == 1) {
  219. $sendTimeWant = isset($post['sendTimeWant']) && !empty($post['sendTimeWant']) ? $post['sendTimeWant'] : date("Y-m-d");
  220. $future = date("Y-m-d", strtotime('+2 day'));
  221. if (strtotime($sendTimeWant) < strtotime($future)) {
  222. //util::fail('请选择时间');
  223. }
  224. $nowTime = strtotime(date("Y-m-d"));
  225. if (strtotime($sendTimeWant) < $nowTime) {
  226. util::fail('不能选择过去时间');
  227. }
  228. }
  229. $ids = array_unique(array_filter(array_column($productList, 'productId')));
  230. $productInfoList = ProductClass::getByIds($ids, null, 'id');
  231. if (!empty($productInfoList)) {
  232. $presellData = [];
  233. $nowTime = strtotime(date("Y-m-d"));
  234. foreach ($productInfoList as $currentInfo) {
  235. if (isset($currentInfo['mainId']) == false || $currentInfo['mainId'] != $ghsMainId) {
  236. util::fail('只能选择同一家的商品哦');
  237. }
  238. $currentName = $currentInfo['name'] ?? '';
  239. if (isset($currentInfo['frontHide']) && $currentInfo['frontHide'] == 1) {
  240. util::fail($currentName . '没有库存请删除');
  241. }
  242. $presell = $currentInfo['presell'] ?? 0;
  243. $presellData[] = $presell;
  244. if ($presell == 1) {
  245. if ($book == 1) {
  246. util::fail('预订时不能选择预售花材');
  247. } else {
  248. if (isset($post['sendTimeWant']) == false || empty($post['sendTimeWant'])) {
  249. util::fail('请选择配送日期');
  250. }
  251. $sendTimeWant = $post['sendTimeWant'];
  252. if (strtotime($sendTimeWant) < $nowTime) {
  253. util::fail('不能选择过去时间');
  254. }
  255. $hasDateStr = $currentInfo['presellDate'] ?? [];
  256. $hasDate = explode(',', trim($hasDateStr));
  257. if (empty($hasDate)) {
  258. util::fail('预售日期有问题,请提醒门店');
  259. }
  260. if (in_array(strtotime($sendTimeWant), $hasDate) == false) {
  261. util::fail("有预售花材在{$sendTimeWant}没到货");
  262. }
  263. $post['presell'] = 1;
  264. }
  265. }
  266. }
  267. if (count($productInfoList) != count($ids)) {
  268. util::fail('存在无效商品');
  269. }
  270. $presellData = array_unique($presellData);
  271. if (count($presellData) > 1) {
  272. util::fail('预售和非预售花材不能一起下单');
  273. }
  274. } else {
  275. util::fail('花材不存在');
  276. }
  277. //供货商预订单最低公斤数要求和每公斤服务费
  278. $ghsInfo['kiloFee'] = $ghsShopInfo->kiloFee ?? 0;
  279. $ghsInfo['miniKilo'] = $ghsShopInfo->miniKilo ?? 0;
  280. $post['product'] = $productList;
  281. $sendType = $post['sendType'] ?? 0;
  282. $transType = $post['transType'] ?? 0;
  283. if (isset($ghsShopInfo->pfLevel) && $ghsShopInfo->pfLevel == 1) {
  284. //昆明发货包装费和运费的计算
  285. $totalWeight = 0;
  286. $totalItemNum = 0;
  287. foreach ($productList as $itemData) {
  288. $bigNum = $itemData['bigNum'] ?? 0;
  289. $thisWeight = $itemData['weight'] ?? 0;
  290. $currentWeight = bcmul($thisWeight, $bigNum, 2);
  291. $totalWeight = bcadd($currentWeight, $totalWeight, 2);
  292. $totalItemNum = bcadd($totalItemNum, $bigNum, 2);
  293. }
  294. $totalItemNum = floatval($totalItemNum);
  295. $kmPackCost = PurchaseClass::getKmPackCost($ghsMainId);
  296. $packCost = 0;
  297. if (!empty($kmPackCost)) {
  298. foreach ($kmPackCost as $itemPack) {
  299. $kiloNum = $itemPack['num'] ?? 0;
  300. if ($kiloNum >= $totalWeight) {
  301. $packCost = $itemPack['amount'] ?? 0;
  302. break;
  303. }
  304. }
  305. }
  306. //同城配送和到店自取免打包费
  307. if ($transType == 4 || $transType == 5) {
  308. $packCost = 0;
  309. }
  310. //如果已经算过一次打包费和运费了,则不再费了
  311. $needAdd = \bizHd\shop\classes\ShopClass::needAddPackCost($ghsShopInfo, $customId);
  312. if ($needAdd == false) {
  313. $packCost = 0;
  314. }
  315. $post['packCost'] = $packCost;
  316. $transCost = dict::getDict('transCost');
  317. $sendCost = 0;
  318. if (!empty($transCost)) {
  319. foreach ($transCost as $trans) {
  320. $sign = $trans['sign'] ?? 0;
  321. if ($sign == $transType) {
  322. if ($sign == 2) {
  323. //冷链物流
  324. $llOption = $trans['option'] ?? [];
  325. if (!empty($llOption)) {
  326. $largeInfo = end($llOption);
  327. $largeNum = $largeInfo['num'] ?? 0;
  328. $largeAmount = $largeInfo['amount'] ?? 0;
  329. $bs = intval($totalItemNum / $largeNum);
  330. if ($bs > 0) {
  331. $addSendCost = bcmul($bs, $largeAmount, 2);
  332. $sendCost = bcadd($sendCost, $addSendCost, 2);
  333. $subNum = bcmul($bs, $largeNum, 2);
  334. $subNum = floatval($subNum);
  335. $totalItemNum = bcsub($totalItemNum, $subNum, 2);
  336. $totalItemNum = floatval($totalItemNum);
  337. }
  338. foreach ($llOption as $miniItem) {
  339. if ($miniItem['num'] >= $totalItemNum) {
  340. $sendCost = bcadd($sendCost, $miniItem['amount'], 2);
  341. break;
  342. }
  343. }
  344. }
  345. } else {
  346. //其它物流
  347. $perKiloCost = $trans['perKiloCost'] ?? 0;
  348. $sendCost = bcmul($perKiloCost, $totalWeight, 3);
  349. $sendCost = round($sendCost, 2);
  350. }
  351. }
  352. }
  353. }
  354. //如果已经算过一次打包费和运费了,则不再费了
  355. $needAdd = \bizHd\shop\classes\ShopClass::needAddPackCost($ghsShopInfo, $customId);
  356. if ($needAdd == false) {
  357. $sendCost = 0;
  358. }
  359. $post['sendCost'] = $sendCost;
  360. //标记为昆明到地方订单
  361. $post['localOrder'] = 1;
  362. } else {
  363. //同城发货包装费和运费的计算
  364. $sendCost = 0;
  365. if ($sendType == dict::getDict('sendType', 'thirdSend')) {
  366. $weight = 0;
  367. foreach ($productList as $itemData) {
  368. $bigNum = $itemData['bigNum'] ?? 0;
  369. $thisWeight = $itemData['weight'] ?? 0;
  370. $currentWeight = bcmul($thisWeight, $bigNum, 2);
  371. $weight = bcadd($currentWeight, $weight, 2);
  372. }
  373. $result = PurchaseClass::getDistanceFee($this->shop, $ghsShopInfo, $weight);
  374. $sendCost = $result['fee'] ?? 0;
  375. }
  376. $post['sendCost'] = $sendCost;
  377. //出车、发快递、发物流可以算包装费
  378. $packCost = 0;
  379. $itemTotalAmount = $post['itemTotalAmount'] ?? 0;
  380. unset($post['itemTotalAmount']);
  381. if ($sendType == dict::getDict('sendType', 'express')) {
  382. $needAdd = \bizHd\shop\classes\ShopClass::needAddPackCost($ghsShopInfo, $customId, $itemTotalAmount);
  383. if ($needAdd) {
  384. $packCost = $ghsShopInfo->packCost ?? 0;
  385. }
  386. }
  387. $post['packCost'] = $packCost;
  388. }
  389. $respond = PurchaseService::createPurchase($post, $ghsInfo);
  390. if ($sendType == 0) {
  391. if (getenv('YII_ENV') == 'production') {
  392. //杭州斗南鲜花批发部,满500,10公里内免费配送,满1000,20公里免费配送
  393. if ($ghsShopId == 4608) {
  394. if ($respond->actPrice < 500) {
  395. $transaction->rollBack();
  396. util::fail('满500元支持免费配送');
  397. }
  398. }
  399. //叶上花,满500元市区免费配送
  400. if ($ghsShopId == 4804) {
  401. if ($respond->actPrice < 500) {
  402. $transaction->rollBack();
  403. util::fail('满500元支持免费配送');
  404. }
  405. }
  406. //花悠星 国恋 勇记 易宝暂时不支持免费配送
  407. if ($ghsShopId == 7687 || $ghsShopId == 7831 || $ghsShopId == 7778 || $ghsShopId == 12003) {
  408. util::fail('暂不支持送货上门,请选其它方式');
  409. }
  410. }
  411. }
  412. if ($sendType == 2) {
  413. if (in_array($ghsShopId, [520, 1489, 13628, 3, 7855, 7687])) {
  414. util::fail('暂时不能使用跑腿');
  415. }
  416. }
  417. if (getenv('YII_ENV') == 'production') {
  418. //昆明花落谁家
  419. if ($ghsShopId == 13398) {
  420. if ($respond->bigNum < 15) {
  421. $transaction->rollBack();
  422. util::fail('不足15扎,请联系店长');
  423. }
  424. }
  425. }
  426. $transaction->commit();
  427. util::success($respond);
  428. } catch (Exception $e) {
  429. $transaction->rollBack();
  430. util::fail();
  431. }
  432. }
  433. //赊账 ssh 2021.1.24
  434. public function actionDebtPay()
  435. {
  436. $get = Yii::$app->request->get();
  437. $orderSn = $get['orderSn'] ?? 0;
  438. $info = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
  439. PurchaseService::valid($info, $this->shopId);
  440. //解决重复和并发提交
  441. $cacheKey = 'hd_debt_pay_' . $orderSn;
  442. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  443. if (!empty($has)) {
  444. util::fail('请稍等...');
  445. }
  446. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 5, 'has']);
  447. if ($info->status == 5) {
  448. util::fail('订单已取消');
  449. }
  450. if ($info->status != 1) {
  451. util::fail('订单不是待付款状态');
  452. }
  453. if ($info->book == 1) {
  454. util::fail('预售不能记欠款');
  455. }
  456. $ghsId = $info->ghsId;
  457. $ghs = GhsClass::getGhsInfo($ghsId);
  458. $customId = $ghs['customId'] ?? 0;
  459. $custom = CustomClass::getCustom($customId);
  460. if (empty($custom)) {
  461. util::fail('没有找到客户');
  462. }
  463. if (isset($custom['debt']) == false || $custom['debt'] == CustomClass::IS_DEBT_NO) {
  464. util::fail('请先申请赊账权限');
  465. }
  466. $connection = Yii::$app->db;//事务处理
  467. $transaction = $connection->beginTransaction();
  468. try {
  469. //延期支付
  470. PurchaseService::debt($info);
  471. $transaction->commit();
  472. if (isset($info->localOrder) && $info->localOrder == 1) {
  473. if ($info->transType != 5 && $info->transType != 4) {
  474. //昆明发货,客户算了一次打包费和运费,第二次就不再算了
  475. $current = date("Y_m_d");
  476. $key = 'ghs_custom_today_has_get_pack_cost_' . $current . '_' . $customId;
  477. Yii::$app->redis->executeCommand('SETEX', [$key, 86400, '1']);
  478. }
  479. } else {
  480. if (isset($info->sendType) && $info->sendType == 4) {
  481. //标记当天已收一次包装费,岭南批发市场用的功能
  482. $current = date("Y_m_d");
  483. $key = 'ghs_custom_today_has_get_pack_cost_' . $current . '_' . $customId;
  484. Yii::$app->redis->executeCommand('SETEX', [$key, 86400, '1']);
  485. }
  486. }
  487. //不是预订单,并且采购人没有开批发店,供货商不是源花汇、小明鲜花、淄博花超、石头花艺,则订单直接完成掉。是预订单,则确认发货时直接完成掉。有多个地方要修改,请搜索关键词zjFinish
  488. $cg = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
  489. if (!empty($cg)) {
  490. if (isset($cg->book) && $cg->book == 0) {
  491. $ghsShopId = $ghs['shopId'] ?? 0;
  492. if (getenv('YII_ENV') == 'production') {
  493. $specialList = [10649, 8042, 16454];
  494. } else {
  495. $specialList = [];
  496. }
  497. if (!in_array($ghsShopId, $specialList)) {
  498. $cgShopId = $cg->shopId ?? 0;
  499. $cgShop = ShopClass::getById($cgShopId, true);
  500. if (!empty($cgShop)) {
  501. if (isset($cgShop->pfShopId) && $cgShop->pfShopId == 0) {
  502. PurchaseClass::confirmTake($cg);
  503. }
  504. }
  505. }
  506. }
  507. }
  508. //app新订单通知
  509. $saleId = $info->saleId ?? 0;
  510. $order = OrderClass::getById($saleId, true);
  511. if (!empty($order)) {
  512. $shopId = $order->shopId ?? 0;
  513. $shop = ShopClass::getById($shopId, true);
  514. if (!empty($shop)) {
  515. //微信通知供货商
  516. //WxMessageClass::ghsHasNewOrderInform($shop, $order);
  517. $noticeText = json_encode(['orderId' => $saleId]);
  518. $noticeKey = "hdCgNoticeGhs";
  519. Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
  520. }
  521. //订单生成时唤起在线打印
  522. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
  523. //有几个地方要同步去修改
  524. if (getenv('YII_ENV') == 'production') {
  525. //源花汇不自动打开小票
  526. $mallOrderNoPrint = [10536];
  527. } else {
  528. $mallOrderNoPrint = [];
  529. }
  530. if (in_array($order->mainId, $mallOrderNoPrint)) {
  531. } else {
  532. OrderClass::onlinePrint($order);
  533. $order->printNum += 1;
  534. $order->save();
  535. }
  536. }
  537. }
  538. } catch (Exception $e) {
  539. $transaction->rollBack();
  540. util::fail('支付失败');
  541. }
  542. util::success($info->attributes);
  543. }
  544. //余额支付 ssh 2021.1.24
  545. public function actionBalancePay()
  546. {
  547. $shopAdmin = $this->shopAdmin;
  548. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  549. util::fail('超管才能操作');
  550. }
  551. $get = Yii::$app->request->get();
  552. $orderSn = $get['orderSn'] ?? 0;
  553. $password = $get['password'] ?? '';
  554. // 重新获取,不加密的用户数据
  555. $admin = AdminClass::getById($this->adminId, true);
  556. if (password_verify($password, $admin->payPassword) == false) {
  557. util::fail('密码错误');
  558. }
  559. $info = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
  560. if (empty($info)) {
  561. util::fail('没有找到采购单');
  562. }
  563. if ($info->status == 5) {
  564. util::fail('订单已取消');
  565. }
  566. if ($info->status != 1) {
  567. util::fail('订单不是待付款状态');
  568. }
  569. PurchaseService::valid($info, $this->shopId);
  570. $connection = Yii::$app->db;//事务处理
  571. $transaction = $connection->beginTransaction();
  572. try {
  573. //余额支付
  574. purchaseService::balancePay($info);
  575. $transaction->commit();
  576. } catch (Exception $e) {
  577. $transaction->rollBack();
  578. util::fail('支付失败');
  579. }
  580. util::success($info->attributes);
  581. }
  582. //采购记录 ssh 2021.1.24
  583. public function actionList()
  584. {
  585. $get = Yii::$app->request->get();
  586. $where = ['shopId' => $this->shopId];
  587. $status = $get['status'] ?? 0;
  588. if (!empty($status)) {
  589. $where['status'] = $status;
  590. }
  591. $respond = PurchaseService::getPurchaseList($where);
  592. $respond['shop'] = $this->shop->attributes;
  593. util::success($respond);
  594. }
  595. //采购详情 ssh 2021.01.25
  596. public function actionDetail()
  597. {
  598. $get = Yii::$app->request->get();
  599. $id = $get['id'] ?? 0;
  600. $info = PurchaseService::getInfo($id, true, true);
  601. if (isset($info['mainId']) == false || $info['mainId'] != $this->mainId) {
  602. //不能注释,分享付款功能要用,客户没有登录也能付款
  603. //util::fail('无法访问');
  604. }
  605. $customId = $info['customId'] ?? 0;
  606. $custom = CustomClass::getById($customId);
  607. $customName = $custom['name'] ?? '';
  608. $customMobile = $custom['mobile'] ?? '';
  609. $info['customName'] = $customName;
  610. $info['customMobile'] = $customMobile;
  611. $hasDebtPay = $custom['debt'] ?? 0;
  612. $book = $info['book'] ?? 0;
  613. $presell = $info['presell'] ?? 0;
  614. //预售不能记欠款
  615. if ($book == 1) {
  616. $hasDebtPay = 0;
  617. }
  618. if ($presell == 1) {
  619. $hasDebtPay = 0;
  620. }
  621. $shop = $this->shop;
  622. $info['pfShopId'] = $shop->pfShopId ?? 0;
  623. $info['hasDebtPay'] = $hasDebtPay;
  624. $info['balance'] = $shop->balance ?? 0;
  625. $getPayType = dict::getDict('getPayType');
  626. $info['getPayType'] = $getPayType;
  627. //获取售后条件
  628. $ghsId = $info['ghsId'] ?? 0;
  629. $ghsInfo = GhsClass::getById($ghsId, true);
  630. if (empty($ghsInfo)) {
  631. util::fail('没有找到供货商');
  632. }
  633. $info['afterSale'] = $ghsInfo->afterSale ?? 1;
  634. //重要,客户看到的电话修改成门店的联系电话
  635. $ghsShopId = $ghsInfo->shopId ?? 0;
  636. $ghsShopInfo = ShopClass::getById($ghsShopId, true);
  637. $info['ghsMobile'] = $ghsShopInfo->telephone ?? '';
  638. util::success($info);
  639. }
  640. //可用的支付方式 ssh 2021.1.25
  641. public function actionPayWay()
  642. {
  643. $button = [
  644. ['type' => 'wxPay', 'show' => 1, 'disable' => 1],
  645. ['type' => 'debtPay', 'show' => 1, 'disable' => 0],
  646. ['type' => 'balancePay', 'show' => 1, 'disable' => 0],
  647. ];
  648. util::success(['button' => $button]);
  649. }
  650. //待结款明细 ssh 2021.1.26
  651. public function actionDebtList()
  652. {
  653. $get = Yii::$app->request->get();
  654. $id = $get['id'] ?? 0;
  655. $info = GhsClass::getGhsInfo($id);
  656. GhsClass::valid($info, $this->shopId);
  657. $where = ['ghsId' => $id, 'debt' => PurchaseClass::DEBT_YES];
  658. $searchTime = $get['searchTime'] ?? '';
  659. if (!empty($searchTime)) {
  660. $startTime = $get['startTime'] ?? '';
  661. $endTime = $get['endTime'] ?? '';
  662. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  663. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  664. }
  665. $respond = PurchaseService::getDebtList($where);
  666. util::success($respond);
  667. }
  668. //微信支付 ssh 2021.4.11
  669. public function actionAliPay()
  670. {
  671. ini_set('date.timezone', 'Asia/Shanghai');
  672. $post = Yii::$app->request->post();
  673. $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
  674. $order = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
  675. if (empty($order)) {
  676. util::fail('订单号无效');
  677. }
  678. if ($order->status == 5) {
  679. util::fail('订单已取消');
  680. }
  681. if ($order->status != 1) {
  682. util::fail('订单不是待付款状态');
  683. }
  684. $deadline = $order->deadline;
  685. $current = time();
  686. if (($current + 50) > strtotime($deadline)) {
  687. util::fail('订单已失效,请重新下单');
  688. }
  689. $ghsId = $order->ghsId ?? 0;
  690. $ghs = GhsClass::getById($ghsId, true);
  691. if (empty($ghs)) {
  692. util::fail('没有供货商信息');
  693. }
  694. $ghsShopId = $ghs->shopId ?? 0;
  695. $ghsShop = ShopClass::getById($ghsShopId, true);
  696. if (empty($ghsShop)) {
  697. util::fail('没有供货商门店信息');
  698. }
  699. if (isset($ghsShop->lklSjNo) && empty($ghsShop->lklSjNo)) {
  700. util::fail('商家支付功能未开通');
  701. }
  702. //已经唤起过微信支付了,根据拉卡拉的规则,需要生成新的订单号
  703. if ($order->changePrice == 2) {
  704. $oldOrderSn = $orderSn;
  705. //老单号需要关单,否则有付款成功的风险,老单号关闭成功了,才能生成新单号
  706. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  707. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  708. $params = [
  709. 'appid' => 'OP00002119',
  710. 'serial_no' => '018b08cfddbd',
  711. 'merchant_no' => $ghsShop->lklSjNo,
  712. 'term_no' => $ghsShop->lklScanTermNo,
  713. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  714. 'lklCertificatePath' => $lklCertificatePath,
  715. ];
  716. $laResource = new Lakala($params);
  717. $closeParams = [
  718. 'orderSn' => $oldOrderSn,
  719. ];
  720. $response = $laResource->cashClose($closeParams);
  721. if (isset($response['code']) == false || $response['code'] != '000000') {
  722. $msg = $response['msg'] ?? '';
  723. noticeUtil::push('注意花店买花更换单号没有成功,单号:' . $oldOrderSn . ',关单没有成功(收银台-支付宝),' . $msg, '15280215347');
  724. }
  725. $newOrderSn = orderSn::getPurchaseSn();
  726. $newGhsOrderSn = orderSn::getGhsOrderSn();
  727. $orderSn = $newOrderSn;
  728. $order->orderSn = $newOrderSn;
  729. $order->save();
  730. PurchaseItemClass::updateByCondition(['orderSn' => $oldOrderSn], ['orderSn' => $newOrderSn]);
  731. $saleId = $order->saleId ?? 0;
  732. $sale = OrderClass::getById($saleId, true);
  733. if (!empty($sale)) {
  734. $oldSaleOrderSn = $sale->orderSn ?? '';
  735. $sale->orderSn = $newGhsOrderSn;
  736. $sale->save();
  737. OrderItemClass::updateByCondition(['orderSn' => $oldSaleOrderSn], ['orderSn' => $newGhsOrderSn]);
  738. }
  739. }
  740. $order->changePrice = 2;
  741. $order->save();
  742. $name = $orderSn;
  743. $totalFee = $order->realPrice;
  744. $purchaseCapital = dict::getDict('capitalType', 'xhPurchase', 'id');
  745. $ghsId = $order->ghsId ?? 0;
  746. $ghs = GhsClass::getById($ghsId, true);
  747. if (empty($ghs)) {
  748. util::fail('没有供货商信息');
  749. }
  750. $ghsShopId = $ghs->shopId ?? 0;
  751. $ghsShop = ShopClass::getById($ghsShopId, true);
  752. if (empty($ghsShop)) {
  753. util::fail('没有供货商门店信息');
  754. }
  755. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  756. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  757. $params = [
  758. 'appid' => 'OP00002119',
  759. 'serial_no' => '018b08cfddbd',
  760. 'merchant_no' => $ghsShop->lklSjNo,
  761. 'term_no' => $ghsShop->lklB2BTermNo,
  762. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  763. 'lklCertificatePath' => $lklCertificatePath,
  764. ];
  765. $laResource = new Lakala($params);
  766. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/cash-pay-callback";
  767. $wxParams = [
  768. 'orderSn' => $orderSn,
  769. 'amount' => $totalFee,
  770. 'capitalType' => $purchaseCapital,
  771. 'notifyUrl' => $notifyUrl,
  772. 'subject' => $name,
  773. ];
  774. $response = $laResource->cashierPay($wxParams);
  775. if (isset($response['code']) == false || $response['code'] != '000000') {
  776. $errMsg = $response['msg'] ?? '';
  777. noticeUtil::push('编号AA90:' . $errMsg, '15280215347');
  778. util::fail('发起支付失败');
  779. }
  780. $counter_url = $response['resp_data']['counter_url'] ? $response['resp_data']['counter_url'] : '';
  781. $new = [
  782. 'payUrl' => $counter_url,
  783. 'orderSn' => $orderSn,
  784. ];
  785. util::success($new);
  786. }
  787. //微信支付 ssh 2021.4.11
  788. public function actionWxPay()
  789. {
  790. ini_set('date.timezone', 'Asia/Shanghai');
  791. $post = Yii::$app->request->post();
  792. $couponId = $post['couponId'] ?? 0;
  793. $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
  794. $order = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
  795. if (empty($order)) {
  796. util::fail('订单号无效');
  797. }
  798. if ($order->status == 5) {
  799. util::fail('订单已取消');
  800. }
  801. if ($order->status != 1) {
  802. util::fail('订单不是待付款状态');
  803. }
  804. $deadline = $order->deadline;
  805. $current = time();
  806. if (($current + 50) > strtotime($deadline)) {
  807. util::fail('订单已失效,请重新下单');
  808. }
  809. $ghsId = $order->ghsId ?? 0;
  810. $ghs = GhsClass::getById($ghsId, true);
  811. if (empty($ghs)) {
  812. util::fail('没有供货商信息');
  813. }
  814. $ghsShopId = $ghs->shopId ?? 0;
  815. $ghsShop = ShopClass::getById($ghsShopId, true);
  816. if (empty($ghsShop)) {
  817. util::fail('没有供货商门店信息');
  818. }
  819. if (isset($ghsShop->lklSjNo) && empty($ghsShop->lklSjNo)) {
  820. util::fail('商家支付功能未开通');
  821. }
  822. //已经唤起过微信支付了,根据拉卡拉的规则,需要生成新的订单号
  823. if ($order->changePrice == 2) {
  824. $oldOrderSn = $orderSn;
  825. //老单号需要关单,否则有付款成功的风险,老单号关闭成功了,才能生成新单号
  826. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  827. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  828. $params = [
  829. 'appid' => 'OP00002119',
  830. 'serial_no' => '018b08cfddbd',
  831. 'merchant_no' => $ghsShop->lklSjNo,
  832. 'term_no' => $ghsShop->lklScanTermNo,
  833. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  834. 'lklCertificatePath' => $lklCertificatePath,
  835. ];
  836. $laResource = new Lakala($params);
  837. $closeParams = [
  838. 'orderSn' => $oldOrderSn,
  839. ];
  840. $response = $laResource->close($closeParams);
  841. if (isset($response['code']) == false || $response['code'] != 'BBS00000') {
  842. $msg = $response['msg'] ?? '';
  843. noticeUtil::push('重点注意,花店买花更换单号没有成功,单号:' . $oldOrderSn . ',关单没有成功,' . $msg, '15280215347');
  844. util::fail('出错了,请重新下一单');
  845. }
  846. $newOrderSn = orderSn::getPurchaseSn();
  847. $newGhsOrderSn = orderSn::getGhsOrderSn();
  848. $orderSn = $newOrderSn;
  849. $order->orderSn = $newOrderSn;
  850. $order->save();
  851. PurchaseItemClass::updateByCondition(['orderSn' => $oldOrderSn], ['orderSn' => $newOrderSn]);
  852. $saleId = $order->saleId ?? 0;
  853. $sale = OrderClass::getById($saleId, true);
  854. if (!empty($sale)) {
  855. $oldSaleOrderSn = $sale->orderSn ?? '';
  856. $sale->orderSn = $newGhsOrderSn;
  857. $sale->save();
  858. OrderItemClass::updateByCondition(['orderSn' => $oldSaleOrderSn], ['orderSn' => $newGhsOrderSn]);
  859. }
  860. }
  861. $id = $order->id;
  862. $order->changePrice = 2;
  863. $order->save();
  864. $name = $orderSn;
  865. $totalFee = $order->realPrice;
  866. $openId = '';
  867. if (isset($post['currentMiniOpenId']) && !empty($post['currentMiniOpenId'])) {
  868. $openId = $post['currentMiniOpenId'];
  869. //noticeUtil::push('花店采购下单时,通过前端获取了openId:' . $openId, '15280215347');
  870. }
  871. if (empty($openId)) {
  872. if (isset($this->admin) && !empty($this->admin)) {
  873. if (isset($this->admin->miniOpenId) && !empty($this->admin->miniOpenId)) {
  874. $openId = $this->admin->miniOpenId;
  875. noticeUtil::push('花店采购下单时,通过数据库获取了openId:' . $openId, '15280215347');
  876. }
  877. }
  878. }
  879. if (empty($openId)) {
  880. $currentShopId = $order->shopId ?? 0;
  881. $currentShop = ShopClass::getById($currentShopId, true);
  882. $currentShopName = $currentShop->merchantName . ' ' . $currentShop->shopName;
  883. $currentMobile = $currentShop->mobile ?? '';
  884. noticeUtil::push("花店采购时,发现没有openId,请跟进是否采购成功。{$currentShopName} {$currentMobile}", '15280215347');
  885. util::success(['hasError' => 1, 'hasNoMiniOpenId' => 1]);
  886. }
  887. $purchaseCapital = dict::getDict('capitalType', 'xhPurchase', 'id');
  888. //花卉宝代为申请的微信支付
  889. $merchantExtend = WxOpenClass::getWxInfo();
  890. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  891. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  892. $params = [
  893. 'appid' => 'OP00002119',
  894. 'serial_no' => '018b08cfddbd',
  895. 'merchant_no' => $ghsShop->lklSjNo,
  896. 'term_no' => $ghsShop->lklScanTermNo,
  897. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  898. 'lklCertificatePath' => $lklCertificatePath,
  899. ];
  900. $laResource = new Lakala($params);
  901. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
  902. $wxParams = [
  903. 'orderSn' => $orderSn,
  904. 'amount' => $totalFee,
  905. 'capitalType' => $purchaseCapital,
  906. 'notifyUrl' => $notifyUrl,
  907. 'wxAppId' => $merchantExtend['miniAppId'],
  908. 'openId' => $openId,
  909. 'subject' => $name,
  910. 'couponId' => $couponId,
  911. ];
  912. $response = $laResource->driveWxPay($wxParams);
  913. if (isset($response['code']) == false || $response['code'] != 'BBS00000') {
  914. $errMsg = $response['msg'] ?? '';
  915. noticeUtil::push('编号99891:' . $errMsg, '15280215347');
  916. util::fail('支付失败');
  917. }
  918. $newParams = isset($response['resp_data']['acc_resp_fields']) ? $response['resp_data']['acc_resp_fields'] : [];
  919. $appId = $newParams['app_id'] ?? '';
  920. $nonceStr = $newParams['nonce_str'] ?? '';
  921. $paySign = $newParams['pay_sign'] ?? '';
  922. $package = $newParams['package'] ?? '';
  923. $signType = $newParams['sign_type'] ?? '';
  924. $timeStamp = $newParams['time_stamp'] ?? '';
  925. $new = [
  926. 'id' => $id,
  927. 'appId' => $appId,
  928. 'nonceStr' => $nonceStr,
  929. 'paySign' => $paySign,
  930. 'package' => $package,
  931. 'signType' => $signType,
  932. 'timeStamp' => $timeStamp,
  933. 'orderSn' => $orderSn,
  934. ];
  935. util::success($new);
  936. }
  937. //计算运费 ssh 20221003
  938. public function actionFreight()
  939. {
  940. $get = Yii::$app->request->get();
  941. $shop = $this->shop;
  942. $shopLat = isset($shop->lat) ? $shop->lat : '';
  943. $shopLong = isset($shop->long) ? $shop->long : '';
  944. if (empty($shopLat) || empty($shopLong)) {
  945. util::success(['distance' => 0, 'showDistance' => 0, 'fee' => 0]);
  946. }
  947. $ghsId = $get['ghsId'] ?? 0;
  948. $ghs = GhsClass::getById($ghsId, true);
  949. if (empty($ghs)) {
  950. util::success(['distance' => 0, 'showDistance' => 0, 'fee' => 0]);
  951. }
  952. $ghsShopId = $ghs->shopId ?? 0;
  953. $ghsShop = ShopClass::getById($ghsShopId, true);
  954. if (empty($ghsShop)) {
  955. util::success(['distance' => 0, 'showDistance' => 0, 'fee' => 0]);
  956. }
  957. $ghsShopLat = isset($ghsShop->lat) ? $ghsShop->lat : '';
  958. $ghsShopLong = isset($ghsShop->long) ? $ghsShop->long : '';
  959. if (empty($ghsShopLat) || empty($ghsShopLong)) {
  960. util::success(['distance' => 0, 'showDistance' => 0, 'fee' => 0]);
  961. }
  962. $weight = $get['weight'] ?? 0;
  963. if (empty($weight)) {
  964. util::success(['distance' => 0, 'showDistance' => 0, 'fee' => 0]);
  965. }
  966. $respond = PurchaseClass::getDistanceFee($this->shop, $ghsShop, $weight);
  967. util::success($respond);
  968. }
  969. //运费计算 lqh 2021.4.12 暂时返回固定值
  970. public function actionFreight2()
  971. {
  972. //lqh 2021.6.25 运费固定返回0
  973. util::success(['sedCost' => 0]);
  974. $post = Yii::$app->request->post();
  975. $ghsId = $post['ghsId'] ?? 0;
  976. //供货商
  977. $ghsInfo = GhsClass::getById($ghsId);
  978. if (empty($ghsInfo)) {
  979. util::fail('没有找到供货商');
  980. }
  981. //花材信息
  982. $productJson = $post['product'] ?? '';
  983. // $productJson = '[{"productId":31993,"bigNum":1,"smallNum":0}]';
  984. if (empty($productJson)) {
  985. util::fail('请选择花材');
  986. }
  987. $productList = json_decode($productJson, true);
  988. if (empty($productList)) {
  989. util::fail('请选择花材');
  990. }
  991. $productList = PurchaseClass::mergeItemInfo($productList);
  992. $weight = 0;
  993. $price = 0;
  994. $productData = ProductClass::getProductMapData($productList);
  995. $bigNum = 0;
  996. foreach ($productList as $key => $val) {
  997. $productId = $val['productId'];
  998. $w = ProductClass::getWeight($val['productId'], $val['bigNum'], $val['smallNum']);
  999. $bigNum += $val['bigNum'];
  1000. $weight = bcadd($w, $weight, 2);
  1001. $ratio = $productData[$productId]['ratio'] ?? 0;
  1002. //大小数量合并多少扎
  1003. $itemNum = ProductClass::mergeItemNum($val['bigNum'], $val['smallNum'], $ratio);
  1004. //售卖价格
  1005. $itemPrice = $productData[$productId]['price'] ?? 0;
  1006. //合计价格
  1007. $price = bcadd($price, bcmul($itemNum, $itemPrice, 2), 2);
  1008. }
  1009. $ghsShopId = $ghsInfo['shopId'] ?? 0;
  1010. $ghsSjId = $ghsInfo['sjId'] ?? 0;
  1011. $sendTime = $post['sendTime'] ?? '';
  1012. if (!empty($sendTime)) {
  1013. //配送时间不为空
  1014. // 预约发单时间(预约时间unix时间戳(10位),精确到分;整分钟为间隔,并且需要至少提前5分钟预约
  1015. $sendTimeInt = strtotime($sendTime);
  1016. $now = time();
  1017. $diff = $sendTimeInt - $now;
  1018. //因服务器写入时间,改为至少提前6分钟
  1019. if ($diff <= 360) {
  1020. util::fail('配送时间至少提前6分钟');
  1021. }
  1022. $sendTime = date('Y-m-d H:i', strtotime($sendTime));
  1023. } else {
  1024. $sendTime = date('Y-m-d H:i', strtotime("+30 minute"));
  1025. }
  1026. //找供货商的客户信息,用里面的配送相关地址信息
  1027. $customId = $ghsInfo['customId'] ?? 0;
  1028. $customInfo = CustomClass::getById($customId);
  1029. if (empty($customInfo)) {
  1030. util::fail('没有找到客户');
  1031. }
  1032. //判断商家是否开启达达,若未开启,则使用自定义运费计算
  1033. $shopNo = ShopExpressClass::getShopNo($ghsSjId, $ghsShopId);
  1034. if (!$shopNo) {
  1035. //使用自定义运费
  1036. //util::fail('供货商暂未开通配送');
  1037. $cost = freight::getCost($ghsInfo['lat'], $ghsInfo['long'], $customInfo['lat'], $customInfo['long'], $weight);
  1038. util::success(['sedCost' => $cost]);
  1039. }
  1040. //组装订单信息
  1041. $info = [];
  1042. //发送放的商家信息,即供货商的相关信息
  1043. $info['sjId'] = $ghsSjId;
  1044. $info['shopId'] = $ghsShopId;
  1045. $info['actPrice'] = $price;//价格
  1046. $info['weight'] = $weight;
  1047. $info['orderSn'] = \common\components\orderSn::getGhsOrderSn();
  1048. $info['bigNum'] = $bigNum;
  1049. //配送地址,当前零售端的门店地址
  1050. $info['customName'] = $customInfo['name'] ?? '';
  1051. $info['customMobile'] = $customInfo['mobile'] ?? '';
  1052. $info['province'] = $customInfo['province'] ?? '';
  1053. $info['city'] = $customInfo['city'] ?? '';;
  1054. $info['address'] = $customInfo['address'] ?? '';;
  1055. $info['floor'] = $customInfo['floor'] ?? '';;
  1056. $info['fullAddress'] = $customInfo['fullAddress'] ?? '';;
  1057. $info['lat'] = $customInfo['lat'] ?? '';;
  1058. $info['long'] = $customInfo['long'] ?? '';;
  1059. $info['sendTime'] = $sendTime;
  1060. $res = DadaExpressServices::queryDeliverFee($info);
  1061. util::success(['sedCost' => $res['fee']]);
  1062. }
  1063. }