PurchaseController.php 51 KB

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