OrderController.php 49 KB

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