PurchaseController.php 51 KB

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