OrderController.php 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156
  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. $quoteResult = DeliveryQuoteUtil::getDeliveryQuote([
  363. 'productList' => $productList,
  364. 'deliveryPlatform' => $post['deliveryPlatform'],
  365. 'deliveryBracketContent' => $post['deliveryBracketContent'], // 平台多报价识别id
  366. 'ghsInfo' => $ghsInfo,
  367. 'custom' => $this->user, // $custom 数据有问题,要是 user
  368. 'order' => [
  369. 'orderSn' => $orderSn,
  370. 'goodsType' => 1, //商品类型:0花束 1花材
  371. 'itemTotalAmount' => $totalNum,
  372. 'remark' => $post['remark'] ?? '',
  373. ],
  374. 'mainId' => $this->mainId,
  375. 'productCount' => $totalNum,
  376. ]);
  377. $sendCost = $quoteResult['sendCost'];
  378. $distance = $quoteResult['sendDistance'];
  379. } catch (\Exception $e) {
  380. util::fail($e->getMessage());
  381. }
  382. $post['sendCost'] = $sendCost;
  383. $post['sendDistance'] = $distance;
  384. noticeUtil::push("零售订单,获取运费:{$sendCost} 重量:{$totalWeight} 距离:{$distance}m 姓名:{$customName} 手机号 {$customMobile} 经纬 {$originalLng} {$originalLat} 金额:{$modifyPrice} 数量:{$totalNum}", '15280215347');
  385. $modifyPrice = bcadd($modifyPrice, $sendCost, 2);
  386. }
  387. $post['modifyPrice'] = $modifyPrice;
  388. //多处调用这个方法,注意同步修改,搜索关键词 createHdNewOrder
  389. $return = \bizHd\order\services\OrderService::createHdOrder($post, $custom, $hasPay);
  390. if (isset($return->shopId)) {
  391. if ($return->shopId == 7610) {
  392. if ($return->actPrice < 200) {
  393. if ($return->sendType == 0) {
  394. util::fail('满200元支持送货上门');
  395. }
  396. }
  397. }
  398. }
  399. if ($return->sendType == 2) {
  400. $ext = ShopExtClass::getByCondition(['shopId' => $return->shopId], true, null, 'id,shopId,thirdSend');
  401. if ($ext->thirdSend == 1) {
  402. util::fail('本店暂不能使用跑腿呢');
  403. }
  404. }
  405. $transaction->commit();
  406. $orderSn = $return->orderSn ?? '';
  407. $orderPrice = $return->orderPrice ?? 0;
  408. $id = $return->id ?? 0;
  409. $getPayType = dict::getDict('getPayType');
  410. util::success(['orderSn' => $orderSn, 'totalPrice' => $orderPrice, 'couponId' => 0, 'id' => $id, 'getPayType' => $getPayType]);
  411. } catch (\Exception $e) {
  412. $transaction->rollBack();
  413. Yii::error("失败原因:" . $e->getMessage());
  414. util::fail('下单失败');
  415. }
  416. }
  417. //商城下单操作 ssh 2019.12.3
  418. public function actionCreateOrder()
  419. {
  420. $post = Yii::$app->request->post();
  421. //避免重复提交
  422. $userId = $this->userId;
  423. util::checkRepeatCommit($userId, 3);
  424. // 判断是否在营业时间窗口
  425. $openTime = $this->shop->openStartTime; // 示例:09:10
  426. $closeTime = $this->shop->openEndTime; // 示例:18:30
  427. if ($openTime != '' && $closeTime != '') {
  428. $openHourMinute = explode(':', $openTime);
  429. $closeHourMinute = explode(':', $closeTime);
  430. $currentHour = date('H');
  431. $currentMinute = date('i');
  432. if ($currentHour < intval($openHourMinute[0]) || ($currentHour == intval($openHourMinute[0]) && $currentMinute < intval($openHourMinute[1]))) {
  433. util::fail('不在营业时间窗口');
  434. }
  435. if ($currentHour > intval($closeHourMinute[0]) || ($currentHour == intval($closeHourMinute[0]) && $currentMinute > intval($closeHourMinute[1]))) {
  436. util::fail('不在营业时间窗口');
  437. }
  438. }
  439. $goodsId = $post['goodsId'] ?? 0;
  440. $goodsNum = isset($post['goodsNum']) && $post['goodsNum'] > 0 ? $post['goodsNum'] : 1;
  441. $sendType = $post['sendType'] ?? dict::getDict('sendType', 'thirdSend');
  442. if (empty($goodsId)) {
  443. util::fail('请选择商品');
  444. }
  445. $mainId = $this->mainId;
  446. $goodsInfo = GoodsClass::getById($goodsId, true);
  447. if (empty($goodsInfo)) {
  448. util::fail('没有找到商品');
  449. }
  450. if ($goodsInfo->mainId != $mainId) {
  451. util::fail('不是你的商品');
  452. }
  453. $stock = $goodsInfo->stock ?? 0;
  454. if ($stock <= 0) {
  455. util::fail('库存不足');
  456. }
  457. //事务处理
  458. $connection = Yii::$app->db;
  459. $transaction = $connection->beginTransaction();
  460. try {
  461. $custom = $this->custom;
  462. if (empty($custom)) {
  463. util::fail('个人信息缺失');
  464. }
  465. $customId = $custom->id ?? 0;
  466. $hd = $this->hd;
  467. $post['customId'] = $customId;
  468. $customName = $custom->name ?? '';
  469. $post['customName'] = $customName;
  470. $post['customNamePy'] = stringUtil::py($customName);
  471. $post['hdId'] = $hd->id ?? 0;
  472. $post['hdName'] = $hd->name ?? '';
  473. $user = $this->user;
  474. $post['bookName'] = $user->name ?? '';
  475. $bookMobile = !empty($post['bookMobile']) && stringUtil::isMobile($post['bookMobile']) ? $post['bookMobile'] : '';
  476. $bookMobile = empty($bookMobile) && !empty($user->mobile) ? $user->mobile : $bookMobile;
  477. $post['bookMobile'] = $bookMobile;
  478. $post['payWay'] = 0;
  479. $shop = $this->shop;
  480. $params = [];
  481. $goodsData = $goodsInfo->attributes;
  482. $ret = \bizHd\goods\classes\GoodsClass::getFinalPrice($goodsData, $shop, $custom, $params);
  483. $goodsInfo->priceType = $ret['priceType'] ?? 0;
  484. if ($goodsInfo->priceType == 0) {
  485. util::fail('没有价格,不能下单哈');
  486. }
  487. $unitPrice = $ret['price'] ?? 0;
  488. if ($unitPrice <= 0) {
  489. util::fail('没有价格,不能下单呢');
  490. }
  491. //计算总金额
  492. $goodsPrice = $unitPrice * $goodsNum;
  493. //计算运费
  494. $sendDistance = 0;
  495. $sendCost = 0;
  496. if ($sendType == dict::getDict('sendType', 'thirdSend')) {
  497. $receiveUserName = $post['receiveUserName'] ?? '';
  498. if (empty($receiveUserName)) {
  499. util::fail('请填写收花人名字');
  500. }
  501. $receiveMobile = $post['receiveMobile'] ?? '';
  502. if (empty($receiveMobile)) {
  503. util::fail('请填写收花人手机号');
  504. }
  505. if (!stringUtil::isMobile($receiveMobile)) {
  506. util::fail('收花人手机号错误');
  507. }
  508. }
  509. $mapSet = ShopClass::hasIntraCity($shop);
  510. $openIntraCity = $mapSet['openIntraCity'] ?? 0;
  511. if ($sendType == dict::getDict('sendType', 'thirdSend') && $openIntraCity != 0) {
  512. // if (dict::getDict('hasMap') == 0) {
  513. // util::fail('不能使用跑腿,请选其它方式');
  514. // }
  515. // $lat = $post['lat'] ?? '';
  516. // $lng = $post['long'] ?? '';
  517. // if ((empty($lat) || empty($lng))) { // 当 hasMap 为1时,经纬数据是必要的
  518. // util::fail('请填写正确地址');
  519. // }
  520. // $address = $post['address'] ?? '';
  521. // $floor = $post['floor'] ?? '';
  522. // $fullAddress = $address . $floor;
  523. // $post['fullAddress'] = $fullAddress;
  524. // $shopLat = $shop->lat ?? '';
  525. // $shopLong = $shop->long ?? '';
  526. // if (empty($shopLat) || empty($shopLong)) {
  527. // util::fail('商家门店地址定位未设置,编号8966');
  528. // }
  529. // $weight = $goodsInfo->weight ?? 0;
  530. // if ($weight <= 0) {
  531. // util::fail('商品没有重量');
  532. // }
  533. // $totalWeight = bcmul($weight, $goodsNum, 2);
  534. // $cargoName = '鲜花'; // 商品名称
  535. // $cargo = [
  536. // 'cargo_name' => $cargoName, // 商品名称
  537. // 'cargo_weight' => intval($totalWeight * 1000), // 单位:克 -- 把千克转换为克 ---- 重量(用户未知)-- 大概
  538. // 'cargo_price' => intval($goodsPrice * 100), // 单位:分 -- 把元转换为分
  539. // 'cargo_type' => IntraCityExpress::GOODS_TYPE_FLOWER,
  540. // 'cargo_num' => $goodsNum
  541. // ];
  542. // $customName = $custom->name;
  543. // $customMobile = $custom->mobile;
  544. // if (empty($post['long']) || empty($post['lat'])) {
  545. // util::fail('位置错误');
  546. // }
  547. // $originalLng = doubleval($post['long']);
  548. // $originalLat = doubleval($post['lat']);
  549. // $city = $post['city'] ?? '';
  550. // $dist = $post['dist'] ?? '';
  551. // $address = $post['address'] ?? '';
  552. // $showAddress = $post['showAddress'] ?? '';
  553. // $userAddress = $city . $dist . $address . "({$showAddress})";
  554. // $main = $this->main;
  555. // $shopLat = $shop->lat ?? '';
  556. // $shopLong = $shop->long ?? '';
  557. // if (empty($shopLat) || empty($shopLong)) {
  558. // util::fail('商家门店地址定位未设置,编号6880');
  559. // }
  560. // $wxStoreId = $main->wxStoreId ?? 0;
  561. // if (empty($wxStoreId)) {
  562. // util::fail('商家还没有开通跑腿功能');
  563. // }
  564. // $orderData = [
  565. // 'wx_store_id' => $wxStoreId,
  566. // 'user_name' => $customName,
  567. // 'user_phone' => $customMobile,
  568. // 'user_lng' => $originalLng,
  569. // 'user_lat' => $originalLat,
  570. // 'user_address' => $userAddress,
  571. // 'cargo' => $cargo,
  572. // ];
  573. // //多处有用到这个方法,需修改请同步修改,搜索关键词 intra_city_express_pre_add
  574. // $result = IntraCityExpress::preAddOrder($orderData);
  575. // $errCode = $result['errcode'] ?? 1;
  576. // if ($errCode != 0) {
  577. // $errMsg = $result['errmsg'] ?? '';
  578. // util::fail('获取运费错误:' . $errMsg);
  579. // }
  580. // $fee = $result['est_fee'] ?? 0;
  581. // $sendDistance = $result['distance'] ?? 0;
  582. // $sendCost = bcdiv($fee, 100, 2);
  583. // //免运费的不收运费
  584. // if ($goodsInfo->freightType == 1) {
  585. // $sendCost = 0;
  586. // }
  587. // noticeUtil::push("零售订单!获取运费:{$sendCost} 重量:{$totalWeight} 距离:{$sendDistance} 姓名:{$customName} 手机号 {$customMobile} 经纬 {$originalLng} {$originalLat} 金额:{$goodsPrice} 数量:{$goodsNum}", '15280215347');
  588. if ($openIntraCity == 2) {
  589. util::fail('不能使用跑腿');
  590. }
  591. $cutomInfo = [
  592. 'name' => $post['receiveUserName'],
  593. 'mobile' => $post['receiveMobile'],
  594. 'fullAddress' => $post['address'],
  595. 'floor' => $post['floor'],
  596. 'dist' => $post[''] ?? '',
  597. 'lat' => $post['lat'],
  598. 'long' => $post['long'],
  599. 'address' => $post['address'],
  600. 'city' => $post['city'],
  601. ];
  602. $cutomInfo = (object)$cutomInfo;
  603. // 生成随机花束订单号
  604. $prefix = 'KD_CS-' . $this->mainId . '-';
  605. $orderSn = $prefix . round(microtime(true) * 1000);
  606. // 使用 DeliveryQuoteUtil 获取配送报价
  607. try {
  608. if ($goodsInfo->weight > 5) {
  609. $goodsInfo->weight = 5;
  610. }
  611. $quoteResult = DeliveryQuoteUtil::getDeliveryQuote([
  612. 'productList' => [['bigNum' => $goodsNum, 'weight' => $goodsInfo->weight]],
  613. 'deliveryPlatform' => $post['deliveryPlatform'],
  614. 'deliveryBracketContent' => $post['deliveryBracketContent'], // 平台多报价识别id
  615. 'ghsInfo' => ['mainId' => $mainId, 'shopId' => $this->shopId],
  616. 'custom' => $cutomInfo,
  617. 'order' => [
  618. 'orderSn' => $orderSn,
  619. 'goodsType' => 0, //商品类型:0花束 1花材
  620. 'itemTotalAmount' => $post['itemTotalAmount'] ?? 0,
  621. 'remark' => $post['remark'] ?? '',
  622. 'freightType' => $goodsInfo->freightType,
  623. ],
  624. 'mainId' => $this->mainId,
  625. 'productCount' => $goodsNum,
  626. ]);
  627. $sendCost = $quoteResult['sendCost'];
  628. $sendDistance = $quoteResult['sendDistance'];
  629. } catch (\Exception $e) {
  630. util::fail($e->getMessage());
  631. }
  632. }
  633. $post['sendDistance'] = $sendDistance;
  634. $post['sendCost'] = $sendCost;
  635. $post['sjId'] = $this->sjId;
  636. $post['shopId'] = $this->shopId;
  637. $post['mainId'] = $mainId;
  638. $post['userId'] = $this->userId;
  639. if ($goodsInfo->priceType == 0) {
  640. util::fail('没有价格,不能下单');
  641. }
  642. $modifyPrice = stringUtil::calcAdd($sendCost, $goodsPrice);
  643. //非门店订单
  644. $post['store'] = 0;
  645. $post['modifyPrice'] = $modifyPrice;
  646. //非自取订单考虑配送时间
  647. $post['reachDate'] = !empty($post['reachDate']) ? $post['reachDate'] : date("Y-m-d");
  648. $sendType = $post['sendType'] ?? 0;
  649. if ($sendType != 1) {
  650. if (empty($post['reachPeriod'])) {
  651. util::fail('请选择配送时间哈');
  652. }
  653. $post['reachTime'] = strtotime($post['reachDate'] . ' ' . $post['reachPeriod']);
  654. }
  655. $now = time();
  656. $expireTime = $now + 1800;//订单30分钟后过期
  657. $post['deadline'] = $expireTime;
  658. $orderSn = orderSn::getOrderSn();
  659. $post['orderSn'] = $orderSn;
  660. $post['fromType'] = dict::getDict('fromType', 'mall');
  661. $post['cash'] = 0;
  662. $post['mainId'] = $mainId;
  663. $post['needPrint'] = dict::getDict('needPrint', 'need');
  664. $hasPay = 0;
  665. $product = [['productId' => $goodsId, 'unitType' => 0, 'property' => 0, 'unitPrice' => $unitPrice, 'num' => $goodsNum]];
  666. $post['product'] = $product;
  667. $return = \bizHd\order\services\OrderService::createHdOrder($post, $custom, $hasPay);
  668. $orderId = $return->id;
  669. $orderSn = $return->orderSn;
  670. $actPrice = $return->actPrice ?? 0;
  671. $transaction->commit();
  672. util::success(['orderSn' => $orderSn, 'totalPrice' => $actPrice, 'couponId' => 0, 'id' => $orderId]);
  673. } catch (Exception $e) {
  674. $transaction->rollBack();
  675. Yii::info("失败原因:" . $e->getMessage());
  676. util::fail('下单失败');
  677. }
  678. }
  679. //下单要用到的相关信息 ssh 2019.12.6
  680. public function actionOrderRelate()
  681. {
  682. $regionTree = RegionService::tree();
  683. //门店名称
  684. $shop = !empty($this->shop) ? $this->shop->attributes : [];
  685. $sjName = $shop['merchantName'] ?? '';
  686. $shopName = $shop['shopName'] ?? '';
  687. $shop['showName'] = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
  688. $avatar = $shop['avatar'] ?? '';
  689. $smallAvatar = imgUtil::groupImg($avatar) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
  690. $shop['smallAvatar'] = $smallAvatar;
  691. $freight = ['first' => 5, 'add' => 2];
  692. $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
  693. $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'thirdMapKey' => $mapKey, 'merchant' => $shop];
  694. util::success($out);
  695. }
  696. //余额支付 ssh 20250410
  697. public function actionBalancePay()
  698. {
  699. $post = Yii::$app->request->post();
  700. $orderSn = $post['orderSn'] ?? '';
  701. //避免重复提交
  702. util::checkRepeatCommit($orderSn, 5);
  703. $connection = Yii::$app->db;
  704. $transaction = $connection->beginTransaction();
  705. try {
  706. $order = OrderClass::getByCondition(['orderSn' => $orderSn], true);
  707. if (empty($order)) {
  708. util::fail('没有找到订单');
  709. }
  710. if ($order->shopId != $this->shopId) {
  711. util::fail('不是你的订单');
  712. }
  713. $payWay = dict::getDict('payWay', 'balancePay');
  714. \bizHd\order\classes\OrderClass::payAfter($order, $payWay);
  715. $transaction->commit();
  716. //解决重复通知,重要
  717. $cacheKey = 'mall_order_balance_pay_' . $orderSn;
  718. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  719. if (empty($has)) {
  720. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 864000, 'has']);
  721. //打印小票和语音播报
  722. $order = \bizHd\order\classes\OrderClass::getByCondition(['orderSn' => $orderSn], true);
  723. \bizHd\order\classes\OrderClass::onlinePrint($order);
  724. $shopId = $order->shopId ?? 0;
  725. $shop = ShopClass::getById($shopId, true);
  726. if (in_array($order->fromType, [1, 3])) {
  727. //您有新的收入提醒
  728. WxMessageClass::gatheringIncomeInform($shop, $order);
  729. }
  730. if ($order->fromType == 2) {
  731. //来自商城的新订单微信通知
  732. WxMessageClass::hdNewOrderInform($shop, $order);
  733. }
  734. }
  735. util::complete('支付成功');
  736. } catch (\Exception $e) {
  737. $transaction->rollBack();
  738. Yii::error("支付原因:" . $e->getMessage());
  739. util::fail('支付失败');
  740. }
  741. }
  742. //获取商城下单要用的微信支付和小程序支付参数 ssh 2019.21.3
  743. public function actionWxPay()
  744. {
  745. ini_set('date.timezone', 'Asia/Shanghai');
  746. $post = Yii::$app->request->post();
  747. $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
  748. $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
  749. $order = OrderService::getByOrderSn($orderSn);
  750. $orderId = $order['id'];
  751. //验证优惠券是否还有效
  752. if (!empty($couponId)) {
  753. CouponService::checkBeforeUse($couponId, $order['prePrice'], $order['userId']);
  754. }
  755. //支付前验证订单有效性
  756. OrderService::checkBeforePay($order);
  757. $name = !empty($order['orderName']) ? $order['orderName'] : '购买花材';
  758. $shop = $this->shop;
  759. if (empty($shop)) {
  760. util::fail('没有找到门店信息');
  761. }
  762. if (isset($shop->shopName) && !empty($shop->shopName)) {
  763. $name .= '(' . $shop->shopName . ')';
  764. }
  765. $totalFee = $order['mainPay'];
  766. $openId = '';
  767. if (!empty($post['miniOpenId'])) {
  768. $openId = $post['miniOpenId'];
  769. //noticeUtil::push('散客买花时,通过前端获取了openId:' . $openId, '15280215347');
  770. }
  771. if (empty($openId)) {
  772. if (isset($this->user['miniOpenId']) && !empty($this->user['miniOpenId'])) {
  773. $openId = $this->user['miniOpenId'];
  774. //noticeUtil::push('散客买花时,通过数据库获取了openId:' . $openId, '15280215347');
  775. }
  776. }
  777. if (empty($openId)) {
  778. util::fail('没有找到openId');
  779. }
  780. $now = time();
  781. $expireTime = $now + 1800;
  782. $updateData = [];
  783. if (isset($order['modPrice']) && $order['modPrice'] == 0) {
  784. $oldOrderSn = $orderSn;
  785. //老单号需要关单,否则有付款成功的风险,老单号关闭成功了,才能生成新单号
  786. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  787. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  788. $params = [
  789. 'appid' => 'OP00002119',
  790. 'serial_no' => '018b08cfddbd',
  791. 'merchant_no' => $shop->lklSjNo,
  792. 'term_no' => $shop->lklScanTermNo,
  793. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  794. 'lklCertificatePath' => $lklCertificatePath,
  795. ];
  796. $laResource = new Lakala($params);
  797. $closeParams = [
  798. 'orderSn' => $oldOrderSn,
  799. ];
  800. $response = $laResource->close($closeParams);
  801. if (!isset($response['code']) || $response['code'] != 'BBS00000') {
  802. $msg = $response['msg'] ?? '';
  803. $lklSjNo = $shop->lklSjNo ?? '';
  804. noticeUtil::push('重点注意,散客买花更换单号没有成功,单号:' . $oldOrderSn . ',关单没有成功,' . $msg . '。商户号:' . $lklSjNo, '15280215347');
  805. util::fail('出错了哦,请重新下一单');
  806. }
  807. $orderSn = orderSn::getOrderSn();
  808. $updateData['orderSn'] = $orderSn;
  809. OrderItemClass::updateByCondition(['orderSn' => $oldOrderSn], ['orderSn' => $orderSn]);
  810. } else {
  811. //已请求的不能再修改价格
  812. $updateData['modPrice'] = 0;
  813. }
  814. if (empty($order['deadline'])) {
  815. $updateData['deadline'] = $expireTime;
  816. }
  817. if (!empty($updateData)) {
  818. OrderService::updateById($orderId, $updateData);
  819. }
  820. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  821. $sjExtend = WxOpenClass::getMallWxInfo();
  822. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  823. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  824. $params = [
  825. 'appid' => 'OP00002119',
  826. 'serial_no' => '018b08cfddbd',
  827. 'merchant_no' => $shop->lklSjNo,
  828. 'term_no' => $shop->lklScanTermNo,
  829. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  830. 'lklCertificatePath' => $lklCertificatePath,
  831. ];
  832. $laResource = new Lakala($params);
  833. $notifyUrl = Yii::$app->params['mallHost'] . "/notice/pay-callback";
  834. $wxParams = [
  835. 'orderSn' => $orderSn,
  836. 'amount' => $totalFee,
  837. 'capitalType' => $capitalType,
  838. 'notifyUrl' => $notifyUrl,
  839. 'wxAppId' => $sjExtend['miniAppId'],
  840. 'openId' => $openId,
  841. 'subject' => $name,
  842. 'couponId' => $couponId,
  843. ];
  844. $response = $laResource->driveWxPay($wxParams);
  845. if (!isset($response['code']) || $response['code'] != 'BBS00000') {
  846. $errMsg = $response['msg'] ?? '';
  847. noticeUtil::push($errMsg, '15280215347');
  848. util::fail('支付失败');
  849. }
  850. $newParams = isset($response['resp_data']['acc_resp_fields']) ? $response['resp_data']['acc_resp_fields'] : [];
  851. $appId = $newParams['app_id'] ?? '';
  852. $nonceStr = $newParams['nonce_str'] ?? '';
  853. $paySign = $newParams['pay_sign'] ?? '';
  854. $package = $newParams['package'] ?? '';
  855. $signType = $newParams['sign_type'] ?? '';
  856. $timeStamp = $newParams['time_stamp'] ?? '';
  857. $new = [
  858. 'id' => $orderId,
  859. 'appId' => $appId,
  860. 'nonceStr' => $nonceStr,
  861. 'paySign' => $paySign,
  862. 'package' => $package,
  863. 'signType' => $signType,
  864. 'timeStamp' => $timeStamp,
  865. 'orderSn' => $orderSn,
  866. ];
  867. util::success($new);
  868. }
  869. //快捷付款订单
  870. public function actionFastPay()
  871. {
  872. ini_set('date.timezone', 'Asia/Shanghai');
  873. $post = Yii::$app->request->post();
  874. $payWay = $post['payWay'] ?? 0;
  875. $shopId = $this->shopId;
  876. $shop = $this->shop;
  877. if (empty($shop)) {
  878. util::fail('没有门店信息');
  879. }
  880. $customId = $this->customId;
  881. $custom = $this->custom;
  882. $hdId = $this->hdId;
  883. $hd = $this->hd;
  884. if (empty($customId) || empty($hdId)) {
  885. //考虑没有登录时的付款
  886. $defaultCustomId = $shop->defaultCustomId ?? 0;
  887. if (empty($defaultCustomId)) {
  888. util::fail('请设置快捷开单的客户');
  889. }
  890. $customId = $defaultCustomId;
  891. $custom = CustomClass::getById($defaultCustomId, true);
  892. if (empty($custom)) {
  893. util::fail('无效的快捷客户');
  894. }
  895. $hdId = $custom->hdId;
  896. $hd = \bizMall\hd\classes\HdClass::getById($hdId, true);
  897. if (empty($hd)) {
  898. util::fail('没有花店信息呢!');
  899. }
  900. }
  901. $post['hdId'] = $hdId;
  902. $post['hdName'] = $hd->name ?? '';
  903. $customName = $custom->name ?? '';
  904. $customPy = $custom->py ?? '';
  905. $post['customName'] = $customName;
  906. $post['customNamePy'] = $customPy;
  907. $post['shopId'] = $shopId;
  908. $post['mainId'] = $this->mainId;
  909. $post['customId'] = $customId;
  910. $prePrice = round($post['prePrice'], 2);
  911. $actPrice = $prePrice;
  912. if ($actPrice <= 0) {
  913. util::fail('请填写付款金额');
  914. }
  915. $post['actPrice'] = $actPrice;
  916. $post['userId'] = $this->userId;
  917. $now = time();
  918. $expireTime = $now + 300;//订单5分钟后过期
  919. $post['createTime'] = date("Y-m-d H:i:s", $now);
  920. $post['deadline'] = date("Y-m-d H:i:s", $expireTime);
  921. $order = ScanPayClass::addOrder($post);
  922. $orderId = $order->id ?? 0;
  923. $orderSn = $order->orderSn ?? '';
  924. $capitalType = dict::getDict('capitalType', 'scanPay', 'id');
  925. if ($payWay == 0) {
  926. //微信
  927. $name = '购买鲜花,扫码付款';
  928. $totalFee = $actPrice;
  929. $user = UserService::getById($this->userId);
  930. //小程序使用miniOpenId
  931. $openId = $user['miniOpenId'];
  932. if (empty($openId)) {
  933. $openId = !empty($post['miniOpenId']) ? $post['miniOpenId'] : '';
  934. }
  935. if (empty($openId)) {
  936. util::fail('没有微信信息');
  937. }
  938. $sjExtend = WxOpenClass::getMallWxInfo();
  939. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  940. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  941. $params = [
  942. 'appid' => 'OP00002119',
  943. 'serial_no' => '018b08cfddbd',
  944. 'merchant_no' => $shop->lklSjNo,
  945. 'term_no' => $shop->lklScanTermNo,
  946. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  947. 'lklCertificatePath' => $lklCertificatePath,
  948. ];
  949. $laResource = new Lakala($params);
  950. $notifyUrl = Yii::$app->params['mallHost'] . "/notice/pay-callback";
  951. $wxParams = [
  952. 'orderSn' => $orderSn,
  953. 'amount' => $totalFee,
  954. 'capitalType' => $capitalType,
  955. 'notifyUrl' => $notifyUrl,
  956. 'wxAppId' => $sjExtend['miniAppId'],
  957. 'openId' => $openId,
  958. 'subject' => $name,
  959. 'couponId' => 0,
  960. ];
  961. $response = $laResource->driveWxPay($wxParams);
  962. if (!isset($response['code']) || $response['code'] != 'BBS00000') {
  963. $errMsg = $response['msg'] ?? '';
  964. noticeUtil::push($errMsg, '15280215347');
  965. util::fail('支付失败');
  966. }
  967. $newParams = $response['resp_data']['acc_resp_fields'] ?? [];
  968. $appId = $newParams['app_id'] ?? '';
  969. $nonceStr = $newParams['nonce_str'] ?? '';
  970. $paySign = $newParams['pay_sign'] ?? '';
  971. $package = $newParams['package'] ?? '';
  972. $signType = $newParams['sign_type'] ?? '';
  973. $timeStamp = $newParams['time_stamp'] ?? '';
  974. $new = [
  975. 'id' => $orderId,
  976. 'appId' => $appId,
  977. 'nonceStr' => $nonceStr,
  978. 'paySign' => $paySign,
  979. 'package' => $package,
  980. 'signType' => $signType,
  981. 'timeStamp' => $timeStamp,
  982. 'orderSn' => $orderSn,
  983. ];
  984. util::success($new);
  985. } elseif ($payWay == 1) {
  986. //支付宝
  987. $totalFee = $actPrice;
  988. $subject = '购买鲜花,扫码付款';
  989. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  990. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  991. $params = [
  992. 'appid' => 'OP00002119',
  993. 'serial_no' => '018b08cfddbd',
  994. 'merchant_no' => $shop->lklSjNo,
  995. 'term_no' => $shop->lklB2BTermNo,
  996. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  997. 'lklCertificatePath' => $lklCertificatePath,
  998. ];
  999. $laResource = new Lakala($params);
  1000. $notifyUrl = Yii::$app->params['mallHost'] . "/notice/cash-pay-callback";
  1001. $cashParams = [
  1002. 'orderSn' => $orderSn,
  1003. 'amount' => $totalFee,
  1004. 'capitalType' => $capitalType,
  1005. 'notifyUrl' => $notifyUrl,
  1006. 'subject' => $subject,
  1007. ];
  1008. $response = $laResource->cashierPay($cashParams);
  1009. if (!isset($response['code']) || $response['code'] != '000000') {
  1010. util::fail('支付失败了');
  1011. }
  1012. $url = $response['resp_data']['counter_url'] ?? '';
  1013. if (empty($url)) {
  1014. util::fail('支付失败');
  1015. }
  1016. util::success(['url' => $url]);
  1017. } elseif ($payWay == 2) {
  1018. //余额支付
  1019. util::fail('暂不支持');
  1020. } else {
  1021. util::fail('无效的支付方式');
  1022. }
  1023. }
  1024. //订单列表 ssh 2019.12.12
  1025. public function actionList()
  1026. {
  1027. $get = Yii::$app->request->get();
  1028. $status = $get['status'] ?? 0;
  1029. $userId = $this->userId;
  1030. $where = ['userId' => $userId];
  1031. if (!empty($status)) {
  1032. $where['status'] = $status;
  1033. }
  1034. $list = OrderService::getOrderList($where);
  1035. util::success($list);
  1036. }
  1037. //订单评价
  1038. public function actionComment()
  1039. {
  1040. $post = Yii::$app->request->post();
  1041. $id = $post['id'];
  1042. $order = OrderClass::getById($id);
  1043. if ($order['grade'] > 0) {
  1044. util::fail('您已经评过了');
  1045. }
  1046. OrderService::comment($post);
  1047. util::complete('提交成功');
  1048. }
  1049. //订单详情 ssh 2019.12.16
  1050. public function actionDetail()
  1051. {
  1052. $id = Yii::$app->request->get('id', 0);
  1053. $detail = OrderClass::getOrderById($id);
  1054. $userId = $this->userId;
  1055. if ($detail['userId'] != $userId) {
  1056. util::fail('不是你的单,不能查看');
  1057. }
  1058. $shOrderMap = [];
  1059. if ($detail['hasForward'] == 1) {
  1060. $shOrderMap = OrderForwardClass::getAllByCondition(['orderId' => $id], null, '*');
  1061. }
  1062. $detail['shOrderMap'] = $shOrderMap;
  1063. util::success($detail);
  1064. }
  1065. //获取详情 ssh 20220512
  1066. public function actionInfo()
  1067. {
  1068. $sn = Yii::$app->request->get('orderSn', '');
  1069. $detail = OrderClass::getOrderBySn($sn);
  1070. util::success($detail);
  1071. }
  1072. }