OrderController.php 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166
  1. <?php
  2. namespace mall\controllers;
  3. use biz\product\classes\ProductClass;
  4. use biz\shop\classes\ShopClass;
  5. use biz\wx\classes\WxMessageClass;
  6. use bizHd\custom\classes\HdClass;
  7. use bizHd\order\classes\ScanPayClass;
  8. use bizHd\wx\classes\WxOpenClass;
  9. use bizMall\custom\classes\CustomClass;
  10. use bizMall\goods\classes\GoodsClass;
  11. use bizMall\order\classes\OrderClass;
  12. use bizMall\order\classes\OrderForwardClass;
  13. use bizMall\order\classes\OrderItemClass;
  14. use bizMall\order\services\OrderService;
  15. use bizMall\promote\services\CouponService;
  16. use bizMall\saas\services\RegionService;
  17. use bizMall\shop\classes\ShopExtClass;
  18. use bizMall\user\services\UserService;
  19. use common\components\dateUtil;
  20. use common\components\delivery\util\DeliveryQuoteUtil;
  21. use common\components\dict;
  22. use common\components\imgUtil;
  23. use common\components\noticeUtil;
  24. use common\components\orderSn;
  25. use common\components\stringUtil;
  26. use Yii;
  27. use common\components\util;
  28. use common\components\lakala\Lakala;
  29. use common\components\IntraCityExpress;
  30. class OrderController extends BaseController
  31. {
  32. //二维码收款使用
  33. public $guestAccess = ['order-relate', 'fast-pay'];
  34. //记账单列表 ssh 20250627
  35. public function actionDebtList()
  36. {
  37. $get = Yii::$app->request->get();
  38. $id = $get['id'] ?? 0;
  39. $where = [];
  40. $where['userId'] = $this->userId;
  41. if (!empty($id)) {
  42. $hd = \bizMall\hd\classes\HdClass::getById($id, true);
  43. if (empty($hd)) {
  44. util::fail('无效的花店');
  45. }
  46. $where['hdId'] = $id;
  47. }
  48. $where['debt'] = 1;
  49. $searchTime = $get['searchTime'] ?? '';
  50. if (!empty($searchTime)) {
  51. $startTime = $get['startTime'] ?? '';
  52. $endTime = $get['endTime'] ?? '';
  53. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  54. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  55. }
  56. $respond = OrderClass::getDebtList($where);
  57. util::success($respond);
  58. }
  59. //新计算运费
  60. public function actionNewFreight()
  61. {
  62. $post = Yii::$app->request->post();
  63. $hasMap = dict::getDict('hasMap');
  64. if ($hasMap == 0) {
  65. util::fail('暂不支持跑腿功能');
  66. }
  67. $mainData = $this->main;
  68. $wxStoreId = $mainData->wxStoreId ?? '';
  69. if (empty($wxStoreId)) {
  70. util::fail('商家还没有开通跑腿');
  71. }
  72. $cargoName = $post['cargo_name']; // 商品名称
  73. $cargo = [
  74. 'cargo_name' => $cargoName, // 商品名称
  75. 'cargo_weight' => intval($post['weight'] * 1000), // 单位:克 -- 把千克转换为克 ---- 重量(用户未知)-- 大概
  76. 'cargo_price' => intval($post['price'] * 100), // 单位:分 -- 把元转换为分
  77. 'cargo_type' => IntraCityExpress::GOODS_TYPE_FLOWER,
  78. 'cargo_num' => intval($post['package_num'])
  79. ];
  80. $originalLng = doubleval($post['user_lng']);
  81. $originalLat = doubleval($post['user_lat']);
  82. $userName = !empty($post['user_name']) ? $post['user_name'] : '游客';
  83. $orderData = [
  84. 'wx_store_id' => $wxStoreId,
  85. 'user_name' => $userName,
  86. 'user_phone' => $post['user_phone'],
  87. 'user_lng' => $originalLng,
  88. 'user_lat' => $originalLat,
  89. 'user_address' => $post['user_address'],
  90. 'cargo' => $cargo,
  91. ];
  92. //多处有用到这个方法,需修改请同步修改,搜索关键词 intra_city_express_pre_add
  93. $result = IntraCityExpress::preAddOrder($orderData);
  94. if ($result['errcode'] === 0) {
  95. util::success($result, "查询成功");
  96. } else {
  97. Yii::error("运费查询失败:" . json_encode($result));
  98. $errMsg = $result['errmsg'] ?? '';
  99. $errCode = $result['errcode'] ?? '';
  100. noticeUtil::push("运费查询失败,原因:" . $errMsg . ",编号:" . $errCode, '15280215347');
  101. util::fail('运费查询失败,请确认是否超过20公斤,编号896');
  102. }
  103. }
  104. //计算运费,请搜索关键词calc_freight,二个方法要合一起 ssh 20221014
  105. public function actionFreight()
  106. {
  107. $get = Yii::$app->request->get();
  108. $shop = $this->shop;
  109. $shopLat = isset($shop->lat) ? $shop->lat : '';
  110. $shopLong = isset($shop->long) ? $shop->long : '';
  111. // 判断地图功能是否正常。0 表示地图定位不可用,全部经纬度数据失效
  112. if (dict::getDict('hasMap') == 0) {
  113. $shopLat = '';
  114. $shopLong = '';
  115. }
  116. if (empty($shopLat) || empty($shopLong)) {
  117. util::success([
  118. 'distance' => 0,
  119. 'showDistance' => 0,
  120. 'fee' => 0,
  121. 'hasMap' => dict::getDict('hasMap'),
  122. 'shop' => 'fail' //门店引起的失败
  123. ]);
  124. }
  125. $userLat = $get['lat'] ?? '';
  126. $userLong = $get['long'] ?? '';
  127. if (empty($userLat) || empty($userLong)) {
  128. util::success([
  129. 'distance' => 0,
  130. 'showDistance' => 0,
  131. 'fee' => 0,
  132. 'hasMap' => dict::getDict('hasMap'),
  133. 'client' => 'fail' //用户端定位失败
  134. ]);
  135. }
  136. $weight = $get['weight'] ?? 0;
  137. if (empty($weight)) {
  138. util::success([
  139. 'distance' => 0,
  140. 'showDistance' => 0,
  141. 'fee' => 0,
  142. 'hasMap' => dict::getDict('hasMap'),
  143. 'weight' => 'fail' //重量不对
  144. ]);
  145. }
  146. //data: {distance: "321", showDistance: "0.3", fee: "12.00"}
  147. $respond = OrderClass::getDistanceFee($userLat, $userLong, $shopLat, $shopLong, $weight);
  148. util::success($respond);
  149. }
  150. //购买花材 ssh 20220511
  151. public function actionBuyItem()
  152. {
  153. $post = Yii::$app->request->post();
  154. $post['sjId'] = $this->sjId;
  155. $post['shopId'] = $this->shopId;
  156. $post['payWay'] = 0;
  157. $post['mainId'] = $this->mainId ?? 0;
  158. $post['userId'] = $this->userId ?? 0;
  159. //避免重复提交
  160. $userId = $this->userId;
  161. util::checkRepeatCommit($userId, 3);
  162. // 判断是否在营业时间窗口
  163. $openTime = $this->shop->openStartTime;
  164. $closeTime = $this->shop->openEndTime;
  165. if ($openTime != '' && $closeTime != '') {
  166. $openHourMinute = explode(':', $openTime);
  167. $closeHourMinute = explode(':', $closeTime);
  168. $currentHour = date('H');
  169. $currentMinute = date('i');
  170. if ($currentHour < intval($openHourMinute[0]) || ($currentHour == intval($openHourMinute[0]) && $currentMinute < intval($openHourMinute[1]))) {
  171. util::fail('不在营业时间窗口');
  172. }
  173. if ($currentHour > intval($closeHourMinute[0]) || ($currentHour == intval($closeHourMinute[0]) && $currentMinute > intval($closeHourMinute[1]))) {
  174. util::fail('不在营业时间窗口');
  175. }
  176. }
  177. //普莲花艺、叶上花、丰行、小武鲜花、九江云朵、源花汇、紫荆不能在花卉宝下单,多处要同步修改,关键词ls_mall_not_open
  178. $mainId = $this->mainId;
  179. if (getenv('YII_ENV') == 'production') {
  180. if (in_array($mainId, [40057, 7779, 42940, 26374, 10536, 65381])) {
  181. util::fail('暂时无法访问');
  182. }
  183. } else {
  184. if (in_array($mainId, [0, 1])) {
  185. util::fail('暂时无法访问');
  186. }
  187. }
  188. $hdId = $post['hdId'] ?? 0;
  189. $hd = HdClass::getById($hdId, true);
  190. if (empty($hd)) {
  191. util::fail('没有找到花店');
  192. }
  193. if ($hd->shopId != $this->shopId) {
  194. util::fail('不是你的花店');
  195. }
  196. $post['hdName'] = $hd->name ?? '';
  197. $customId = $hd->customId ?? 0;
  198. $custom = CustomClass::getById($customId, true);
  199. if (empty($custom)) {
  200. util::fail('没有找到客户');
  201. }
  202. $customName = $custom->name ?? '';
  203. $post['customId'] = $customId;
  204. $post['customName'] = $customName;
  205. $post['customNamePy'] = stringUtil::py($customName);
  206. $now = time();
  207. //订单30分钟后过期
  208. $expireTime = $now + 1800;
  209. $post['deadline'] = $expireTime;
  210. //商城
  211. $post['fromType'] = dict::getDict('fromType', 'mall');
  212. $productJson = $post['product'] ?? '';
  213. if (empty($productJson) && empty($groupId)) {
  214. util::fail('请选择商品');
  215. }
  216. $productList = json_decode($productJson, true);
  217. if (empty($productList)) {
  218. util::fail('请选择商品');
  219. }
  220. $ids = array_unique(array_filter(array_column($productList, 'productId')));
  221. $productInfoList = productClass::getByIds($ids, null, 'id');
  222. if (!empty($productInfoList)) {
  223. $presellData = [];
  224. $nowTime = strtotime(date("Y-m-d"));
  225. foreach ($productInfoList as $currentInfo) {
  226. if (!isset($currentInfo['mainId']) || $currentInfo['mainId'] != $this->mainId) {
  227. util::fail('只能选择同一家的商品哦');
  228. }
  229. $currentName = $currentInfo['name'] ?? '';
  230. $presell = $currentInfo['presell'] ?? 0;
  231. $presellData[] = $presell;
  232. if ($presell == 1) {
  233. if (empty($post['reachDate'])) {
  234. util::fail('请选择配送或取货日期');
  235. }
  236. $sendTimeWant = $post['reachDate'];
  237. if (strtotime($sendTimeWant) < $nowTime) {
  238. util::fail('不能选择过去时间');
  239. }
  240. $hasDateStr = $currentInfo['presellDate'] ?? [];
  241. $hasDate = explode(',', trim($hasDateStr));
  242. if (empty($hasDate)) {
  243. util::fail('预售日期有问题,请提醒门店');
  244. }
  245. if (!in_array(strtotime($sendTimeWant), $hasDate)) {
  246. util::fail("有预售花材在{$sendTimeWant}没到货");
  247. }
  248. $post['presell'] = 1;
  249. }
  250. }
  251. if (count($productInfoList) != count($ids)) {
  252. util::fail('存在无效商品');
  253. }
  254. $presellData = array_unique($presellData);
  255. if (count($presellData) > 1) {
  256. util::fail('预售和非预售花材不能一起下单');
  257. }
  258. } else {
  259. util::fail('花材不存在');
  260. }
  261. $connection = Yii::$app->db;
  262. $transaction = $connection->beginTransaction();
  263. try {
  264. $orderValidTime = !getenv('ORDER_VALID_TIME') ? 600 : getenv('ORDER_VALID_TIME');
  265. $post['deadline'] = time() + $orderValidTime;
  266. $post['reachDate'] = !empty($post['reachDate']) ? $post['reachDate'] : date("Y-m-d");
  267. $post['needPrint'] = dict::getDict('needPrint', 'need');
  268. $user = $this->user;
  269. $post['bookMobile'] = $user->mobile ?? '';
  270. $post['bookName'] = $user->name ?? '';
  271. $hasPay = 0;
  272. $modifyPrice = 0;
  273. //各个等级对应的price addPrice字段
  274. $priceMap = \bizGhs\custom\classes\CustomClass::$levelPriceKeyMap;
  275. $addPriceMap = \bizGhs\custom\classes\CustomClass::$levelAddPriceKeyMap;
  276. $totalWeight = 0;
  277. $totalNum = 0;
  278. foreach ($productList as $eleKey => $element) {
  279. $level = 0;
  280. $productId = $element['productId'];
  281. $current = $productInfoList[$productId];
  282. if (empty($current)) {
  283. util::fail('有商品信息没有找到');
  284. }
  285. $price = \bizGhs\product\classes\ProductClass::getFinalPrice($current, $level, $priceMap, $addPriceMap);
  286. $num = $element['num'] ?? 0;
  287. $currentTotal = bcmul($price, $num, 2);
  288. $modifyPrice = bcadd($modifyPrice, $currentTotal, 2);
  289. $productList[$eleKey]['unitPrice'] = $price;
  290. $weight = $current['weight'] ?? 0;
  291. $currentWeight = bcmul($num, $weight, 2);
  292. $totalWeight = bcadd($totalWeight, $currentWeight, 2);
  293. $totalNum = bcadd($totalNum, $num);
  294. }
  295. $post['product'] = $productList;
  296. //不能前端传运费过来,只能通过跑腿接口计算出来
  297. unset($post['sendCost']);
  298. $mapSet = ShopClass::hasIntraCity($this->shop);
  299. $openIntraCity = $mapSet['openIntraCity'] ?? 0;
  300. if (isset($post['sendType']) && $post['sendType'] == 2 && $openIntraCity != 0) {
  301. if ($openIntraCity == 2) {
  302. util::fail('不能使用跑腿');
  303. }
  304. $cargoName = '花材'; // 商品名称
  305. $cargo = [
  306. 'cargo_name' => $cargoName, // 商品名称
  307. 'cargo_weight' => intval($totalWeight * 1000), // 单位:克 -- 把千克转换为克 ---- 重量(用户未知)-- 大概
  308. 'cargo_price' => intval($modifyPrice * 100), // 单位:分 -- 把元转换为分
  309. 'cargo_type' => IntraCityExpress::GOODS_TYPE_FLOWER,
  310. 'cargo_num' => $totalNum
  311. ];
  312. $customName = $custom->name;
  313. $customMobile = $custom->mobile;
  314. if (empty($post['long']) || empty($post['lat'])) {
  315. util::fail('位置错误');
  316. }
  317. $originalLng = doubleval($post['long']);
  318. $originalLat = doubleval($post['lat']);
  319. // $city = $post['city'] ?? '';
  320. // $dist = $post['dist'] ?? '';
  321. // $address = $post['address'] ?? '';
  322. // $showAddress = $post['showAddress'] ?? '';
  323. // $userAddress = $city . $dist . $address . "({$showAddress})";
  324. // $main = $this->main;
  325. $shop = $this->shop;
  326. $shopLat = $shop->lat ?? '';
  327. $shopLong = $shop->long ?? '';
  328. if (empty($shopLat) || empty($shopLong)) {
  329. util::fail('商家门店地址定位未设置,编号263');
  330. }
  331. // $wxStoreId = $main->wxStoreId ?? 0;
  332. // if (empty($wxStoreId)) {
  333. // util::fail('商家还没有开通跑腿功能');
  334. // }
  335. // $orderData = [
  336. // 'wx_store_id' => $wxStoreId,
  337. // 'user_name' => $customName,
  338. // 'user_phone' => $customMobile,
  339. // 'user_lng' => $originalLng,
  340. // 'user_lat' => $originalLat,
  341. // 'user_address' => $userAddress,
  342. // 'cargo' => $cargo,
  343. // ];
  344. // //多处有用到这个方法,需修改请同步修改,搜索关键词 intra_city_express_pre_add
  345. // $result = IntraCityExpress::preAddOrder($orderData);
  346. // $errCode = $result['errcode'] ?? 1;
  347. // if ($errCode != 0) {
  348. // $errMsg = $result['errmsg'] ?? '';
  349. // util::fail('获取运费错误:' . $errMsg);
  350. // }
  351. // $fee = $result['est_fee'] ?? 0;
  352. // $distance = $result['distance'] ?? 0;
  353. // $sendCost = bcdiv($fee, 100, 2);
  354. $distance = 0;
  355. $sendCost = 0;
  356. //生成随机订单号,不要跟原来的混起来,跑腿-销售单-
  357. $prefix = 'PT-XSD-' . $this->mainId . '-';
  358. $orderSn = $prefix . round(microtime(true) * 1000);
  359. $ghsInfo = ['mainId' => $this->mainId, 'shopId' => $this->shopId];
  360. // 这儿要调用跑腿接口计算运费和距离
  361. try {
  362. if (empty($post['deliveryPlatform'])) {
  363. util::fail('请选择跑腿');
  364. }
  365. $quoteResult = DeliveryQuoteUtil::getDeliveryQuote([
  366. 'productList' => $productList,
  367. 'deliveryPlatform' => $post['deliveryPlatform'],
  368. 'deliveryBracketContent' => $post['deliveryBracketContent'], // 平台多报价识别id
  369. 'ghsInfo' => $ghsInfo,
  370. 'custom' => $this->user, // $custom 数据有问题,要是 user
  371. 'order' => [
  372. 'orderSn' => $orderSn,
  373. 'goodsType' => 1, //商品类型:0花束 1花材
  374. 'itemTotalAmount' => $modifyPrice,
  375. 'remark' => $post['remark'] ?? '',
  376. ],
  377. 'mainId' => $this->mainId,
  378. 'productCount' => $totalNum,
  379. ]);
  380. $sendCost = $quoteResult['sendCost'];
  381. $distance = $quoteResult['sendDistance'];
  382. } catch (\Exception $e) {
  383. util::fail($e->getMessage());
  384. }
  385. $post['sendCost'] = $sendCost;
  386. $post['sendDistance'] = $distance;
  387. noticeUtil::push("零售订单(花材),获取运费:{$sendCost} 重量:{$totalWeight} 距离:{$distance}m 姓名:{$customName} 手机号 {$customMobile} 金额:{$modifyPrice} 数量:{$totalNum}", '15280215347');
  388. $modifyPrice = bcadd($modifyPrice, $sendCost, 2);
  389. }
  390. $post['modifyPrice'] = $modifyPrice;
  391. //多处调用这个方法,注意同步修改,搜索关键词 createHdNewOrder
  392. $return = \bizHd\order\services\OrderService::createHdOrder($post, $custom, $hasPay);
  393. if (isset($return->shopId)) {
  394. if ($return->shopId == 7610) {
  395. if ($return->actPrice < 200) {
  396. if ($return->sendType == 0) {
  397. util::fail('满200元支持送货上门');
  398. }
  399. }
  400. }
  401. }
  402. if ($return->sendType == 2) {
  403. $ext = ShopExtClass::getByCondition(['shopId' => $return->shopId], true, null, 'id,shopId,thirdSend');
  404. if ($ext->thirdSend == 1) {
  405. util::fail('本店暂不能使用跑腿呢');
  406. }
  407. }
  408. $transaction->commit();
  409. $orderSn = $return->orderSn ?? '';
  410. $orderPrice = $return->orderPrice ?? 0;
  411. $id = $return->id ?? 0;
  412. $getPayType = dict::getDict('getPayType');
  413. util::success(['orderSn' => $orderSn, 'totalPrice' => $orderPrice, 'couponId' => 0, 'id' => $id, 'getPayType' => $getPayType]);
  414. } catch (\Exception $e) {
  415. $transaction->rollBack();
  416. Yii::error("失败原因:" . $e->getMessage());
  417. util::fail('下单失败');
  418. }
  419. }
  420. //商城下单操作 ssh 2019.12.3
  421. public function actionCreateOrder()
  422. {
  423. $post = Yii::$app->request->post();
  424. //避免重复提交
  425. $userId = $this->userId;
  426. util::checkRepeatCommit($userId, 3);
  427. // 判断是否在营业时间窗口
  428. $openTime = $this->shop->openStartTime; // 示例:09:10
  429. $closeTime = $this->shop->openEndTime; // 示例:18:30
  430. if ($openTime != '' && $closeTime != '') {
  431. $openHourMinute = explode(':', $openTime);
  432. $closeHourMinute = explode(':', $closeTime);
  433. $currentHour = date('H');
  434. $currentMinute = date('i');
  435. if ($currentHour < intval($openHourMinute[0]) || ($currentHour == intval($openHourMinute[0]) && $currentMinute < intval($openHourMinute[1]))) {
  436. util::fail('不在营业时间窗口');
  437. }
  438. if ($currentHour > intval($closeHourMinute[0]) || ($currentHour == intval($closeHourMinute[0]) && $currentMinute > intval($closeHourMinute[1]))) {
  439. util::fail('不在营业时间窗口');
  440. }
  441. }
  442. $goodsId = $post['goodsId'] ?? 0;
  443. $goodsNum = isset($post['goodsNum']) && $post['goodsNum'] > 0 ? $post['goodsNum'] : 1;
  444. $sendType = $post['sendType'] ?? dict::getDict('sendType', 'thirdSend');
  445. if (empty($goodsId)) {
  446. util::fail('请选择商品');
  447. }
  448. $mainId = $this->mainId;
  449. $goodsInfo = GoodsClass::getById($goodsId, true);
  450. if (empty($goodsInfo)) {
  451. util::fail('没有找到商品');
  452. }
  453. if ($goodsInfo->mainId != $mainId) {
  454. util::fail('不是你的商品');
  455. }
  456. $stock = $goodsInfo->stock ?? 0;
  457. if ($stock <= 0) {
  458. util::fail('库存不足');
  459. }
  460. //事务处理
  461. $connection = Yii::$app->db;
  462. $transaction = $connection->beginTransaction();
  463. try {
  464. $custom = $this->custom;
  465. if (empty($custom)) {
  466. util::fail('个人信息缺失');
  467. }
  468. $customId = $custom->id ?? 0;
  469. $hd = $this->hd;
  470. $post['customId'] = $customId;
  471. $customName = $custom->name ?? '';
  472. $post['customName'] = $customName;
  473. $post['customNamePy'] = stringUtil::py($customName);
  474. $post['hdId'] = $hd->id ?? 0;
  475. $post['hdName'] = $hd->name ?? '';
  476. $user = $this->user;
  477. $post['bookName'] = $user->name ?? '';
  478. $bookMobile = !empty($post['bookMobile']) && stringUtil::isMobile($post['bookMobile']) ? $post['bookMobile'] : '';
  479. $bookMobile = empty($bookMobile) && !empty($user->mobile) ? $user->mobile : $bookMobile;
  480. $post['bookMobile'] = $bookMobile;
  481. $post['payWay'] = 0;
  482. $shop = $this->shop;
  483. $params = [];
  484. $goodsData = $goodsInfo->attributes;
  485. $ret = \bizHd\goods\classes\GoodsClass::getFinalPrice($goodsData, $shop, $custom, $params);
  486. $goodsInfo->priceType = $ret['priceType'] ?? 0;
  487. if ($goodsInfo->priceType == 0) {
  488. util::fail('没有价格,不能下单哈');
  489. }
  490. $unitPrice = $ret['price'] ?? 0;
  491. if ($unitPrice <= 0) {
  492. util::fail('没有价格,不能下单呢');
  493. }
  494. //计算总金额
  495. $goodsPrice = $unitPrice * $goodsNum;
  496. //计算运费
  497. $sendDistance = 0;
  498. $sendCost = 0;
  499. if ($sendType == dict::getDict('sendType', 'thirdSend')) {
  500. $receiveUserName = $post['receiveUserName'] ?? '';
  501. if (empty($receiveUserName)) {
  502. util::fail('请填写收花人名字');
  503. }
  504. $receiveMobile = $post['receiveMobile'] ?? '';
  505. if (empty($receiveMobile)) {
  506. util::fail('请填写收花人手机号');
  507. }
  508. if (!stringUtil::isMobile($receiveMobile)) {
  509. util::fail('收花人手机号错误');
  510. }
  511. }
  512. $mapSet = ShopClass::hasIntraCity($shop);
  513. $openIntraCity = $mapSet['openIntraCity'] ?? 0;
  514. if ($sendType == dict::getDict('sendType', 'thirdSend') && $openIntraCity != 0) {
  515. // if (dict::getDict('hasMap') == 0) {
  516. // util::fail('不能使用跑腿,请选其它方式');
  517. // }
  518. // $lat = $post['lat'] ?? '';
  519. // $lng = $post['long'] ?? '';
  520. // if ((empty($lat) || empty($lng))) { // 当 hasMap 为1时,经纬数据是必要的
  521. // util::fail('请填写正确地址');
  522. // }
  523. // $address = $post['address'] ?? '';
  524. // $floor = $post['floor'] ?? '';
  525. // $fullAddress = $address . $floor;
  526. // $post['fullAddress'] = $fullAddress;
  527. // $shopLat = $shop->lat ?? '';
  528. // $shopLong = $shop->long ?? '';
  529. // if (empty($shopLat) || empty($shopLong)) {
  530. // util::fail('商家门店地址定位未设置,编号8966');
  531. // }
  532. // $weight = $goodsInfo->weight ?? 0;
  533. // if ($weight <= 0) {
  534. // util::fail('商品没有重量');
  535. // }
  536. // $totalWeight = bcmul($weight, $goodsNum, 2);
  537. // $cargoName = '鲜花'; // 商品名称
  538. // $cargo = [
  539. // 'cargo_name' => $cargoName, // 商品名称
  540. // 'cargo_weight' => intval($totalWeight * 1000), // 单位:克 -- 把千克转换为克 ---- 重量(用户未知)-- 大概
  541. // 'cargo_price' => intval($goodsPrice * 100), // 单位:分 -- 把元转换为分
  542. // 'cargo_type' => IntraCityExpress::GOODS_TYPE_FLOWER,
  543. // 'cargo_num' => $goodsNum
  544. // ];
  545. // $customName = $custom->name;
  546. // $customMobile = $custom->mobile;
  547. // if (empty($post['long']) || empty($post['lat'])) {
  548. // util::fail('位置错误');
  549. // }
  550. // $originalLng = doubleval($post['long']);
  551. // $originalLat = doubleval($post['lat']);
  552. // $city = $post['city'] ?? '';
  553. // $dist = $post['dist'] ?? '';
  554. // $address = $post['address'] ?? '';
  555. // $showAddress = $post['showAddress'] ?? '';
  556. // $userAddress = $city . $dist . $address . "({$showAddress})";
  557. // $main = $this->main;
  558. // $shopLat = $shop->lat ?? '';
  559. // $shopLong = $shop->long ?? '';
  560. // if (empty($shopLat) || empty($shopLong)) {
  561. // util::fail('商家门店地址定位未设置,编号6880');
  562. // }
  563. // $wxStoreId = $main->wxStoreId ?? 0;
  564. // if (empty($wxStoreId)) {
  565. // util::fail('商家还没有开通跑腿功能');
  566. // }
  567. // $orderData = [
  568. // 'wx_store_id' => $wxStoreId,
  569. // 'user_name' => $customName,
  570. // 'user_phone' => $customMobile,
  571. // 'user_lng' => $originalLng,
  572. // 'user_lat' => $originalLat,
  573. // 'user_address' => $userAddress,
  574. // 'cargo' => $cargo,
  575. // ];
  576. // //多处有用到这个方法,需修改请同步修改,搜索关键词 intra_city_express_pre_add
  577. // $result = IntraCityExpress::preAddOrder($orderData);
  578. // $errCode = $result['errcode'] ?? 1;
  579. // if ($errCode != 0) {
  580. // $errMsg = $result['errmsg'] ?? '';
  581. // util::fail('获取运费错误:' . $errMsg);
  582. // }
  583. // $fee = $result['est_fee'] ?? 0;
  584. // $sendDistance = $result['distance'] ?? 0;
  585. // $sendCost = bcdiv($fee, 100, 2);
  586. // //免运费的不收运费
  587. // if ($goodsInfo->freightType == 1) {
  588. // $sendCost = 0;
  589. // }
  590. // noticeUtil::push("零售订单!获取运费:{$sendCost} 重量:{$totalWeight} 距离:{$sendDistance} 姓名:{$customName} 手机号 {$customMobile} 经纬 {$originalLng} {$originalLat} 金额:{$goodsPrice} 数量:{$goodsNum}", '15280215347');
  591. if ($openIntraCity == 2) {
  592. util::fail('不能使用跑腿');
  593. }
  594. $cutomInfo = [
  595. 'name' => $post['receiveUserName'],
  596. 'mobile' => $post['receiveMobile'],
  597. 'fullAddress' => $post['address'],
  598. 'floor' => $post['floor'],
  599. 'dist' => $post[''] ?? '',
  600. 'lat' => $post['lat'],
  601. 'long' => $post['long'],
  602. 'address' => $post['address'],
  603. 'city' => $post['city'],
  604. ];
  605. $cutomInfo = (object)$cutomInfo;
  606. // 生成随机花束订单号
  607. $prefix = 'KD_CS-' . $this->mainId . '-';
  608. $orderSn = $prefix . round(microtime(true) * 1000);
  609. // 使用 DeliveryQuoteUtil 获取配送报价
  610. try {
  611. if ($goodsInfo->weight > 5) {
  612. $goodsInfo->weight = 5;
  613. }
  614. if (empty($post['deliveryPlatform'])) {
  615. util::fail('请选择跑腿');
  616. }
  617. $quoteResult = DeliveryQuoteUtil::getDeliveryQuote([
  618. 'productList' => [['bigNum' => $goodsNum, 'weight' => $goodsInfo->weight]],
  619. 'deliveryPlatform' => $post['deliveryPlatform'],
  620. 'deliveryBracketContent' => $post['deliveryBracketContent'], // 平台多报价识别id
  621. 'ghsInfo' => ['mainId' => $mainId, 'shopId' => $this->shopId],
  622. 'custom' => $cutomInfo,
  623. 'order' => [
  624. 'orderSn' => $orderSn,
  625. 'goodsType' => 0, //商品类型:0花束 1花材
  626. 'itemTotalAmount' => $goodsPrice,
  627. 'remark' => $post['remark'] ?? '',
  628. 'freightType' => $goodsInfo->freightType,
  629. ],
  630. 'mainId' => $this->mainId,
  631. 'productCount' => $goodsNum,
  632. ]);
  633. $sendCost = $quoteResult['sendCost'];
  634. $sendDistance = $quoteResult['sendDistance'];
  635. noticeUtil::push("零售订单(花束),获取运费:{$sendCost} 重量:{$goodsInfo->weight} 距离:{$sendDistance}m 姓名:{$customName} 金额:{$goodsPrice} 数量:{$goodsNum}");
  636. } catch (\Exception $e) {
  637. util::fail($e->getMessage());
  638. }
  639. }
  640. $post['sendDistance'] = $sendDistance;
  641. $post['sendCost'] = $sendCost;
  642. $post['sjId'] = $this->sjId;
  643. $post['shopId'] = $this->shopId;
  644. $post['mainId'] = $mainId;
  645. $post['userId'] = $this->userId;
  646. if ($goodsInfo->priceType == 0) {
  647. util::fail('没有价格,不能下单');
  648. }
  649. $modifyPrice = stringUtil::calcAdd($sendCost, $goodsPrice);
  650. //非门店订单
  651. $post['store'] = 0;
  652. $post['modifyPrice'] = $modifyPrice;
  653. //非自取订单考虑配送时间
  654. $post['reachDate'] = !empty($post['reachDate']) ? $post['reachDate'] : date("Y-m-d");
  655. $sendType = $post['sendType'] ?? 0;
  656. if ($sendType != 1) {
  657. if (empty($post['reachPeriod'])) {
  658. util::fail('请选择配送时间哈');
  659. }
  660. $post['reachTime'] = strtotime($post['reachDate'] . ' ' . $post['reachPeriod']);
  661. }
  662. $now = time();
  663. $expireTime = $now + 1800;//订单30分钟后过期
  664. $post['deadline'] = $expireTime;
  665. $orderSn = orderSn::getOrderSn();
  666. $post['orderSn'] = $orderSn;
  667. $post['fromType'] = dict::getDict('fromType', 'mall');
  668. $post['cash'] = 0;
  669. $post['mainId'] = $mainId;
  670. $post['needPrint'] = dict::getDict('needPrint', 'need');
  671. $hasPay = 0;
  672. $product = [['productId' => $goodsId, 'unitType' => 0, 'property' => 0, 'unitPrice' => $unitPrice, 'num' => $goodsNum]];
  673. $post['product'] = $product;
  674. $return = \bizHd\order\services\OrderService::createHdOrder($post, $custom, $hasPay);
  675. $orderId = $return->id;
  676. $orderSn = $return->orderSn;
  677. $actPrice = $return->actPrice ?? 0;
  678. $transaction->commit();
  679. util::success(['orderSn' => $orderSn, 'totalPrice' => $actPrice, 'couponId' => 0, 'id' => $orderId]);
  680. } catch (Exception $e) {
  681. $transaction->rollBack();
  682. Yii::info("失败原因:" . $e->getMessage());
  683. util::fail('下单失败');
  684. }
  685. }
  686. //下单要用到的相关信息 ssh 2019.12.6
  687. public function actionOrderRelate()
  688. {
  689. $regionTree = RegionService::tree();
  690. //门店名称
  691. $shop = !empty($this->shop) ? $this->shop->attributes : [];
  692. $sjName = $shop['merchantName'] ?? '';
  693. $shopName = $shop['shopName'] ?? '';
  694. $shop['showName'] = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  695. $avatar = $shop['avatar'] ?? '';
  696. $smallAvatar = imgUtil::groupImg($avatar) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
  697. $shop['smallAvatar'] = $smallAvatar;
  698. $freight = ['first' => 5, 'add' => 2];
  699. $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
  700. $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'thirdMapKey' => $mapKey, 'merchant' => $shop];
  701. util::success($out);
  702. }
  703. //余额支付 ssh 20250410
  704. public function actionBalancePay()
  705. {
  706. $post = Yii::$app->request->post();
  707. $orderSn = $post['orderSn'] ?? '';
  708. //避免重复提交
  709. util::checkRepeatCommit($orderSn, 5);
  710. $connection = Yii::$app->db;
  711. $transaction = $connection->beginTransaction();
  712. try {
  713. $order = OrderClass::getByCondition(['orderSn' => $orderSn], true);
  714. if (empty($order)) {
  715. util::fail('没有找到订单');
  716. }
  717. if ($order->shopId != $this->shopId) {
  718. util::fail('不是你的订单');
  719. }
  720. $payWay = dict::getDict('payWay', 'balancePay');
  721. \bizHd\order\classes\OrderClass::payAfter($order, $payWay);
  722. $transaction->commit();
  723. //解决重复通知,重要
  724. $cacheKey = 'mall_order_balance_pay_' . $orderSn;
  725. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  726. if (empty($has)) {
  727. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 864000, 'has']);
  728. //打印小票和语音播报
  729. $order = \bizHd\order\classes\OrderClass::getByCondition(['orderSn' => $orderSn], true);
  730. \bizHd\order\classes\OrderClass::onlinePrint($order);
  731. $shopId = $order->shopId ?? 0;
  732. $shop = ShopClass::getById($shopId, true);
  733. if (in_array($order->fromType, [1, 3])) {
  734. //您有新的收入提醒
  735. WxMessageClass::gatheringIncomeInform($shop, $order);
  736. }
  737. if ($order->fromType == 2) {
  738. //来自商城的新订单微信通知
  739. WxMessageClass::hdNewOrderInform($shop, $order);
  740. }
  741. }
  742. util::complete('支付成功');
  743. } catch (\Exception $e) {
  744. $transaction->rollBack();
  745. Yii::error("支付原因:" . $e->getMessage());
  746. util::fail('支付失败');
  747. }
  748. }
  749. //获取商城下单要用的微信支付和小程序支付参数 ssh 2019.21.3
  750. public function actionWxPay()
  751. {
  752. ini_set('date.timezone', 'Asia/Shanghai');
  753. $post = Yii::$app->request->post();
  754. $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
  755. $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
  756. $order = OrderService::getByOrderSn($orderSn);
  757. $orderId = $order['id'];
  758. //验证优惠券是否还有效
  759. if (!empty($couponId)) {
  760. CouponService::checkBeforeUse($couponId, $order['prePrice'], $order['userId']);
  761. }
  762. //支付前验证订单有效性
  763. OrderService::checkBeforePay($order);
  764. $name = !empty($order['orderName']) ? $order['orderName'] : '购买花材';
  765. $shop = $this->shop;
  766. if (empty($shop)) {
  767. util::fail('没有找到门店信息');
  768. }
  769. if (isset($shop->shopName) && !empty($shop->shopName)) {
  770. $name .= '(' . $shop->shopName . ')';
  771. }
  772. $totalFee = $order['mainPay'];
  773. $openId = '';
  774. if (!empty($post['miniOpenId'])) {
  775. $openId = $post['miniOpenId'];
  776. //noticeUtil::push('散客买花时,通过前端获取了openId:' . $openId, '15280215347');
  777. }
  778. if (empty($openId)) {
  779. if (isset($this->user['miniOpenId']) && !empty($this->user['miniOpenId'])) {
  780. $openId = $this->user['miniOpenId'];
  781. //noticeUtil::push('散客买花时,通过数据库获取了openId:' . $openId, '15280215347');
  782. }
  783. }
  784. if (empty($openId)) {
  785. util::fail('没有找到openId');
  786. }
  787. $now = time();
  788. $expireTime = $now + 1800;
  789. $updateData = [];
  790. if (isset($order['modPrice']) && $order['modPrice'] == 0) {
  791. $oldOrderSn = $orderSn;
  792. //老单号需要关单,否则有付款成功的风险,老单号关闭成功了,才能生成新单号
  793. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  794. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  795. $params = [
  796. 'appid' => 'OP00002119',
  797. 'serial_no' => '018b08cfddbd',
  798. 'merchant_no' => $shop->lklSjNo,
  799. 'term_no' => $shop->lklScanTermNo,
  800. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  801. 'lklCertificatePath' => $lklCertificatePath,
  802. ];
  803. $laResource = new Lakala($params);
  804. $closeParams = [
  805. 'orderSn' => $oldOrderSn,
  806. ];
  807. $response = $laResource->close($closeParams);
  808. if (!isset($response['code']) || $response['code'] != 'BBS00000') {
  809. $msg = $response['msg'] ?? '';
  810. $lklSjNo = $shop->lklSjNo ?? '';
  811. noticeUtil::push('重点注意,散客买花更换单号没有成功,单号:' . $oldOrderSn . ',关单没有成功,' . $msg . '。商户号:' . $lklSjNo, '15280215347');
  812. util::fail('出错了哦,请重新下一单');
  813. }
  814. $orderSn = orderSn::getOrderSn();
  815. $updateData['orderSn'] = $orderSn;
  816. OrderItemClass::updateByCondition(['orderSn' => $oldOrderSn], ['orderSn' => $orderSn]);
  817. } else {
  818. //已请求的不能再修改价格
  819. $updateData['modPrice'] = 0;
  820. }
  821. if (empty($order['deadline'])) {
  822. $updateData['deadline'] = $expireTime;
  823. }
  824. if (!empty($updateData)) {
  825. OrderService::updateById($orderId, $updateData);
  826. }
  827. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  828. $sjExtend = WxOpenClass::getMallWxInfo();
  829. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  830. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  831. $params = [
  832. 'appid' => 'OP00002119',
  833. 'serial_no' => '018b08cfddbd',
  834. 'merchant_no' => $shop->lklSjNo,
  835. 'term_no' => $shop->lklScanTermNo,
  836. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  837. 'lklCertificatePath' => $lklCertificatePath,
  838. ];
  839. $laResource = new Lakala($params);
  840. $notifyUrl = Yii::$app->params['mallHost'] . "/notice/pay-callback";
  841. $wxParams = [
  842. 'orderSn' => $orderSn,
  843. 'amount' => $totalFee,
  844. 'capitalType' => $capitalType,
  845. 'notifyUrl' => $notifyUrl,
  846. 'wxAppId' => $sjExtend['miniAppId'],
  847. 'openId' => $openId,
  848. 'subject' => $name,
  849. 'couponId' => $couponId,
  850. ];
  851. $response = $laResource->driveWxPay($wxParams);
  852. if (!isset($response['code']) || $response['code'] != 'BBS00000') {
  853. $errMsg = $response['msg'] ?? '';
  854. noticeUtil::push($errMsg, '15280215347');
  855. util::fail('支付失败');
  856. }
  857. $newParams = isset($response['resp_data']['acc_resp_fields']) ? $response['resp_data']['acc_resp_fields'] : [];
  858. $appId = $newParams['app_id'] ?? '';
  859. $nonceStr = $newParams['nonce_str'] ?? '';
  860. $paySign = $newParams['pay_sign'] ?? '';
  861. $package = $newParams['package'] ?? '';
  862. $signType = $newParams['sign_type'] ?? '';
  863. $timeStamp = $newParams['time_stamp'] ?? '';
  864. $new = [
  865. 'id' => $orderId,
  866. 'appId' => $appId,
  867. 'nonceStr' => $nonceStr,
  868. 'paySign' => $paySign,
  869. 'package' => $package,
  870. 'signType' => $signType,
  871. 'timeStamp' => $timeStamp,
  872. 'orderSn' => $orderSn,
  873. ];
  874. util::success($new);
  875. }
  876. //快捷付款订单
  877. public function actionFastPay()
  878. {
  879. ini_set('date.timezone', 'Asia/Shanghai');
  880. $post = Yii::$app->request->post();
  881. $payWay = $post['payWay'] ?? 0;
  882. $shopId = $this->shopId;
  883. $shop = $this->shop;
  884. if (empty($shop)) {
  885. util::fail('没有门店信息');
  886. }
  887. $customId = $this->customId;
  888. $custom = $this->custom;
  889. $hdId = $this->hdId;
  890. $hd = $this->hd;
  891. if (empty($customId) || empty($hdId)) {
  892. //考虑没有登录时的付款
  893. $defaultCustomId = $shop->defaultCustomId ?? 0;
  894. if (empty($defaultCustomId)) {
  895. util::fail('请设置快捷开单的客户');
  896. }
  897. $customId = $defaultCustomId;
  898. $custom = CustomClass::getById($defaultCustomId, true);
  899. if (empty($custom)) {
  900. util::fail('无效的快捷客户');
  901. }
  902. $hdId = $custom->hdId;
  903. $hd = \bizMall\hd\classes\HdClass::getById($hdId, true);
  904. if (empty($hd)) {
  905. util::fail('没有花店信息呢!');
  906. }
  907. }
  908. $post['hdId'] = $hdId;
  909. $post['hdName'] = $hd->name ?? '';
  910. $customName = $custom->name ?? '';
  911. $customPy = $custom->py ?? '';
  912. $post['customName'] = $customName;
  913. $post['customNamePy'] = $customPy;
  914. $post['shopId'] = $shopId;
  915. $post['mainId'] = $this->mainId;
  916. $post['customId'] = $customId;
  917. $prePrice = round($post['prePrice'], 2);
  918. $actPrice = $prePrice;
  919. if ($actPrice <= 0) {
  920. util::fail('请填写付款金额');
  921. }
  922. $post['actPrice'] = $actPrice;
  923. $post['userId'] = $this->userId;
  924. $now = time();
  925. $expireTime = $now + 300;//订单5分钟后过期
  926. $post['createTime'] = date("Y-m-d H:i:s", $now);
  927. $post['deadline'] = date("Y-m-d H:i:s", $expireTime);
  928. $order = ScanPayClass::addOrder($post);
  929. $orderId = $order->id ?? 0;
  930. $orderSn = $order->orderSn ?? '';
  931. $capitalType = dict::getDict('capitalType', 'scanPay', 'id');
  932. if ($payWay == 0) {
  933. //微信
  934. $name = '购买鲜花,扫码付款';
  935. $totalFee = $actPrice;
  936. $user = UserService::getById($this->userId);
  937. //小程序使用miniOpenId
  938. $openId = $user['miniOpenId'];
  939. if (empty($openId)) {
  940. $openId = !empty($post['miniOpenId']) ? $post['miniOpenId'] : '';
  941. }
  942. if (empty($openId)) {
  943. util::fail('没有微信信息');
  944. }
  945. $sjExtend = WxOpenClass::getMallWxInfo();
  946. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  947. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  948. $params = [
  949. 'appid' => 'OP00002119',
  950. 'serial_no' => '018b08cfddbd',
  951. 'merchant_no' => $shop->lklSjNo,
  952. 'term_no' => $shop->lklScanTermNo,
  953. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  954. 'lklCertificatePath' => $lklCertificatePath,
  955. ];
  956. $laResource = new Lakala($params);
  957. $notifyUrl = Yii::$app->params['mallHost'] . "/notice/pay-callback";
  958. $wxParams = [
  959. 'orderSn' => $orderSn,
  960. 'amount' => $totalFee,
  961. 'capitalType' => $capitalType,
  962. 'notifyUrl' => $notifyUrl,
  963. 'wxAppId' => $sjExtend['miniAppId'],
  964. 'openId' => $openId,
  965. 'subject' => $name,
  966. 'couponId' => 0,
  967. ];
  968. $response = $laResource->driveWxPay($wxParams);
  969. if (!isset($response['code']) || $response['code'] != 'BBS00000') {
  970. $errMsg = $response['msg'] ?? '';
  971. noticeUtil::push($errMsg, '15280215347');
  972. util::fail('支付失败');
  973. }
  974. $newParams = $response['resp_data']['acc_resp_fields'] ?? [];
  975. $appId = $newParams['app_id'] ?? '';
  976. $nonceStr = $newParams['nonce_str'] ?? '';
  977. $paySign = $newParams['pay_sign'] ?? '';
  978. $package = $newParams['package'] ?? '';
  979. $signType = $newParams['sign_type'] ?? '';
  980. $timeStamp = $newParams['time_stamp'] ?? '';
  981. $new = [
  982. 'id' => $orderId,
  983. 'appId' => $appId,
  984. 'nonceStr' => $nonceStr,
  985. 'paySign' => $paySign,
  986. 'package' => $package,
  987. 'signType' => $signType,
  988. 'timeStamp' => $timeStamp,
  989. 'orderSn' => $orderSn,
  990. ];
  991. util::success($new);
  992. } elseif ($payWay == 1) {
  993. //支付宝
  994. $totalFee = $actPrice;
  995. $subject = '购买鲜花,扫码付款';
  996. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  997. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  998. $params = [
  999. 'appid' => 'OP00002119',
  1000. 'serial_no' => '018b08cfddbd',
  1001. 'merchant_no' => $shop->lklSjNo,
  1002. 'term_no' => $shop->lklB2BTermNo,
  1003. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  1004. 'lklCertificatePath' => $lklCertificatePath,
  1005. ];
  1006. $laResource = new Lakala($params);
  1007. $notifyUrl = Yii::$app->params['mallHost'] . "/notice/cash-pay-callback";
  1008. $cashParams = [
  1009. 'orderSn' => $orderSn,
  1010. 'amount' => $totalFee,
  1011. 'capitalType' => $capitalType,
  1012. 'notifyUrl' => $notifyUrl,
  1013. 'subject' => $subject,
  1014. ];
  1015. $response = $laResource->cashierPay($cashParams);
  1016. if (!isset($response['code']) || $response['code'] != '000000') {
  1017. util::fail('支付失败了');
  1018. }
  1019. $url = $response['resp_data']['counter_url'] ?? '';
  1020. if (empty($url)) {
  1021. util::fail('支付失败');
  1022. }
  1023. util::success(['url' => $url]);
  1024. } elseif ($payWay == 2) {
  1025. //余额支付
  1026. util::fail('暂不支持');
  1027. } else {
  1028. util::fail('无效的支付方式');
  1029. }
  1030. }
  1031. //订单列表 ssh 2019.12.12
  1032. public function actionList()
  1033. {
  1034. $get = Yii::$app->request->get();
  1035. $status = $get['status'] ?? 0;
  1036. $userId = $this->userId;
  1037. $where = ['userId' => $userId];
  1038. if (!empty($status)) {
  1039. $where['status'] = $status;
  1040. }
  1041. $list = OrderService::getOrderList($where);
  1042. util::success($list);
  1043. }
  1044. //订单评价
  1045. public function actionComment()
  1046. {
  1047. $post = Yii::$app->request->post();
  1048. $id = $post['id'];
  1049. $order = OrderClass::getById($id);
  1050. if ($order['grade'] > 0) {
  1051. util::fail('您已经评过了');
  1052. }
  1053. OrderService::comment($post);
  1054. util::complete('提交成功');
  1055. }
  1056. //订单详情 ssh 2019.12.16
  1057. public function actionDetail()
  1058. {
  1059. $id = Yii::$app->request->get('id', 0);
  1060. $detail = OrderClass::getOrderById($id);
  1061. $userId = $this->userId;
  1062. if ($detail['userId'] != $userId) {
  1063. util::fail('不是你的单,不能查看');
  1064. }
  1065. $shOrderMap = [];
  1066. if ($detail['hasForward'] == 1) {
  1067. $shOrderMap = OrderForwardClass::getAllByCondition(['orderId' => $id], null, '*');
  1068. }
  1069. $detail['shOrderMap'] = $shOrderMap;
  1070. util::success($detail);
  1071. }
  1072. //获取详情 ssh 20220512
  1073. public function actionInfo()
  1074. {
  1075. $sn = Yii::$app->request->get('orderSn', '');
  1076. $detail = OrderClass::getOrderBySn($sn);
  1077. util::success($detail);
  1078. }
  1079. }