PurchaseController.php 47 KB

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