OrderController.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. <?php
  2. namespace hd\controllers;
  3. use biz\sj\services\MerchantAssetService;
  4. use biz\sj\services\MerchantExtendService;
  5. use biz\sj\services\MerchantService;
  6. use bizGhs\product\classes\ProductClass;
  7. use bizHd\custom\classes\CustomClass;
  8. use bizHd\goods\classes\GoodsClass;
  9. use bizHd\merchant\services\ShopService;
  10. use bizHd\order\classes\OrderClass;
  11. use bizHd\order\classes\OrderSendClass;
  12. use bizHd\order\services\OrderService;
  13. use bizHd\saas\services\RegionService;
  14. use bizHd\user\services\UserService;
  15. use bizGhs\order\classes\OrderItemClass;
  16. use common\components\dict;
  17. use common\components\dateUtil;
  18. use common\services\xhPayToolService;
  19. use Yii;
  20. use common\components\util;
  21. use common\components\stringUtil;
  22. use bizHd\goods\services\GoodsService;
  23. use bizHd\merchant\services\ExpressService;
  24. use bizHd\order\services\OrderGoodsService;
  25. use bizHd\promote\services\CouponService;
  26. use common\components\httpUtil;
  27. class OrderController extends BaseController
  28. {
  29. public $guestAccess = ['order-relate', 'fast-pay', 'create-order', 'list'];
  30. //开单操作 ssh 20220316
  31. public function actionCreateOrder()
  32. {
  33. $post = Yii::$app->request->post();
  34. $post['sjId'] = $this->sjId;
  35. $post['shopId'] = $this->shopId;
  36. $post['payWay'] = $this->isWx == true ? 0 : 1;
  37. $post['mainId'] = $this->mainId ?? 0;
  38. $now = time();
  39. //订单30分钟后过期
  40. $expireTime = $now + 1800;
  41. $post['deadline'] = $expireTime;
  42. //商城
  43. $post['fromType'] = 1;
  44. //客户
  45. $customId = $post['customId'] ?? 0;
  46. if (empty($customId)) {
  47. $customId = isset($this->shop->skCustomId) ? $this->shop->skCustomId : 0;
  48. }
  49. if (empty($customId)) {
  50. util::fail('没有找到客户');
  51. }
  52. $custom = CustomClass::getById($customId);
  53. if (empty($custom)) {
  54. util::fail('没有找到客户哦');
  55. }
  56. $post['customId'] = $customId;
  57. $hasPay = $post['hasPay'] ?? dict::getDict('hasPay', 'unPay');
  58. $productJson = $post['product'] ?? '';
  59. if (empty($productJson)) {
  60. util::fail('请选择商品');
  61. }
  62. $productList = json_decode($productJson, true);
  63. if (empty($productList)) {
  64. util::fail('请选择商品');
  65. }
  66. $connection = Yii::$app->db;//事务处理
  67. $transaction = $connection->beginTransaction();
  68. try {
  69. $post['product'] = $productList;
  70. $post['deadline'] = date("Y-m-d H:i:s", strtotime('+360 day'));
  71. $return = OrderService::createFinishOrder($post, $custom, $hasPay);
  72. $transaction->commit();
  73. util::success($return);
  74. } catch (\Exception $e) {
  75. $transaction->rollBack();
  76. Yii::error("下单失败原因:" . $e->getMessage());
  77. util::fail('下单失败');
  78. }
  79. }
  80. //下单要用到的相关信息 ssh 2019.12.6
  81. public function actionOrderRelate()
  82. {
  83. $regionTree = RegionService::tree();
  84. $shop = $this->shop->attributes;
  85. $freight = MerchantExtendService::getFreight($this->sjExtend);
  86. $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
  87. $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'txMapKey' => $mapKey, 'merchant' => $shop];
  88. util::success($out);
  89. }
  90. //余额支付 ssh 2019.12.6
  91. public function actionBalancePay()
  92. {
  93. $post = Yii::$app->request->post();
  94. $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
  95. $payPassword = isset($post['payPassword']) ? $post['payPassword'] : 0;
  96. $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
  97. //验证优惠券是否还有效
  98. if (!empty($couponId)) {
  99. CouponService::checkBeforeUse($couponId, $order['prePrice'], $order['userId']);
  100. }
  101. $order = OrderService::getByOrderSn($orderSn);
  102. $userId = $this->adminId;
  103. $user = UserService::getUserInfo($userId);
  104. //验证支付密码是否正确
  105. UserService::validPayPassword($payPassword, $user);
  106. //支付前验证订单有效性
  107. OrderService::checkBeforePay($order, $this->adminId);
  108. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  109. $totalFee = $order['prePrice'];
  110. $sourceType = 0;
  111. $discountData = OrderService::getDiscountPrice(['price' => $totalFee, 'sourceType' => $sourceType, 'couponId' => $couponId, 'userId' => $this->adminId]);
  112. $actPrice = $discountData['price'];
  113. $callbackParams = [];
  114. $respond = xhPayToolService::balancePay($callbackParams, $orderSn, $actPrice, $capitalType, $couponId);
  115. $balance = isset($respond['balance']) ? $respond['balance'] : 0;
  116. util::success(['discountAmount' => $discountData['discountAmount'], 'discountType' => $discountData['discountType'], 'balance' => $balance]);
  117. }
  118. //获取商城下单要用的微信支付和小程序支付参数 ssh 2019.21.3
  119. public function actionWxPay()
  120. {
  121. ini_set('date.timezone', 'Asia/Shanghai');
  122. $post = Yii::$app->request->post();
  123. $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
  124. $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
  125. $order = OrderService::getByOrderSn($orderSn);
  126. $orderId = $order['id'];
  127. //验证优惠券是否还有效
  128. if (!empty($couponId)) {
  129. CouponService::checkBeforeUse($couponId, $order['prePrice'], $order['userId']);
  130. }
  131. //支付前验证订单有效性
  132. OrderService::checkBeforePay($order, $this->adminId);
  133. $name = isset($order['orderName']) && !empty($order['orderName']) ? $order['orderName'] : '购买商品';
  134. $totalFee = $order['realPrice'];
  135. //小程序使用miniOpenId
  136. if (httpUtil::isMiniProgram()) {
  137. $openId = $this->user['miniOpenId'];
  138. } else {
  139. $openId = $this->user['openId'];
  140. }
  141. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  142. //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
  143. $wxPayType = 0;
  144. if (httpUtil::isMiniProgram()) {
  145. $wxPayType = 1;
  146. }
  147. $attach = "couponId=" . $couponId . "&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType;
  148. //订单30分钟后过期
  149. $now = time();
  150. $expireTime = $now + 1800;
  151. $wx = Yii::getAlias("@vendor/weixin");
  152. require_once($wx . '/lib/WxPay.Api.php');
  153. require_once($wx . '/example/WxPay.JsApiPay.php');
  154. $input = new \WxPayUnifiedOrder();
  155. $input->SetBody($name);
  156. $input->SetOut_trade_no($orderSn);
  157. $input->SetTotal_fee($totalFee * 100);
  158. $input->SetTime_start(date("YmdHis", $now));
  159. $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
  160. $input->SetTime_expire(date("YmdHis", $expireTime));
  161. $input->SetNotify_url(Yii::$app->params['hdHost'] . '/notice/wx-callback/');
  162. $input->SetTrade_type("JSAPI");
  163. //花卉宝代为申请的微信支付
  164. $merchantExtend = $this->sjExtend->attributes;
  165. if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
  166. $input->SetSub_openid($openId);
  167. } else {
  168. $input->SetOpenid($openId);
  169. }
  170. //小程序使用miniAppId
  171. if (httpUtil::isMiniProgram()) {
  172. $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
  173. }
  174. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
  175. $tools = new \JsApiPay();
  176. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
  177. $newParams = json_decode($jsApiParameters, true);
  178. //已请求微信不能修改价格
  179. $updateData = [];
  180. $updateData['modPrice'] = 0;
  181. if (empty($order['deadline'])) {
  182. $updateData['deadline'] = $expireTime;
  183. }
  184. OrderService::updateById($orderId, $updateData);
  185. util::success($newParams);
  186. }
  187. //快捷付款订单
  188. public function actionFastPay()
  189. {
  190. ini_set('date.timezone', 'Asia/Shanghai');
  191. $post = Yii::$app->request->post();
  192. $payWay = isset($post['payWay']) ? $post['payWay'] : 0;
  193. $shopId = !empty($this->shopId) ? $this->shopId : ShopService::getDefaultShopId($this->sj);
  194. //验证门店是否有效
  195. $shopInfo = ShopService::getById($shopId);
  196. ShopService::valid($shopInfo, $this->sjId);
  197. $post['shopId'] = $shopId;
  198. //默认门店订单
  199. $store = isset($post['store']) ? $post['store'] : 1;
  200. $post['store'] = $store;
  201. //来源 0微信 1支付宝 2小程序 3朋友圈 4美团
  202. $sourceType = $this->isWx ? 0 : 1;
  203. if (httpUtil::isMiniProgram()) {
  204. $sourceType = 2;
  205. }
  206. $sourceType = isset($post['sourceType']) ? $post['sourceType'] : 0;
  207. //兼容旧系统sourceType=3表示朋友圈来源
  208. $fromType = $sourceType == 3 ? 2 : 0;
  209. $fromType = isset($post['fromType']) && !empty($post['fromType']) ? $post['fromType'] : $fromType;
  210. $post['userId'] = $this->adminId;
  211. $custom = $this->custom;
  212. $post['bookName'] = $custom['userName'] ?? '';
  213. $bookMobile = isset($post['bookMobile']) && !empty($post['bookMobile']) && stringUtil::isMobile($post['bookMobile']) ? $post['bookMobile'] : '';
  214. $bookMobile = empty($bookMobile) && isset($custom['mobile']) && !empty($custom['mobile']) ? $custom['mobile'] : $bookMobile;
  215. $post['bookMobile'] = $bookMobile;
  216. $prePrice = round($post['prePrice'], 2);
  217. $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
  218. $discountData = OrderService::getDiscountPrice(['price' => $prePrice, 'sourceType' => $sourceType, 'couponId' => $couponId, 'userId' => $this->adminId]);
  219. $actPrice = $discountData['price'];
  220. $post['discountType'] = $discountData['discountType'];
  221. $post['discountAmount'] = $discountData['discountAmount'];
  222. $post['actPrice'] = $actPrice;
  223. $post['realPrice'] = $actPrice;
  224. $post['payStyle'] = 0;
  225. $post['sjId'] = $this->sjId;
  226. $now = time();
  227. $expireTime = $now + 300;//订单5分钟后过期
  228. $post['createTime'] = date("Y-m-d H:i:s", $now);
  229. $post['deadline'] = $expireTime;
  230. if ($actPrice <= 0) {
  231. util::fail('请填写正确的金额');
  232. }
  233. //微信支付订单提交不能修改价格
  234. $post['modPrice'] = $this->isWx ? 0 : 1;
  235. $post['sourceType'] = $sourceType;
  236. $post['goodsNum'] = 1;
  237. $post['fromType'] = $fromType;
  238. $order = OrderService::addOrder($post);
  239. $orderId = $order['id'];
  240. $orderSn = $order['orderSn'];
  241. $sjId = $this->sjId;
  242. if ($payWay == 0) {
  243. $orderId = $order['id'];
  244. $name = '购买商品';
  245. $totalFee = $actPrice;
  246. $user = UserService::getById($this->adminId);
  247. $openId = isset($user['openId']) ? $user['openId'] : 0;
  248. if (httpUtil::isMiniProgram()) {
  249. //小程序使用miniOpenId
  250. $openId = $user['miniOpenId'];
  251. }
  252. if (empty($openId)) {
  253. util::fail('没有找到客户的openId');
  254. }
  255. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  256. //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
  257. $wxPayType = 0;
  258. if (httpUtil::isMiniProgram()) {
  259. $wxPayType = 1;
  260. }
  261. $attach = 'capitalType=' . $capitalType . '&couponId=' . $couponId . '&wxPayType=' . $wxPayType;
  262. $wx = Yii::getAlias("@vendor/weixin");
  263. require_once($wx . '/lib/WxPay.Api.php');
  264. require_once($wx . '/example/WxPay.JsApiPay.php');
  265. $input = new \WxPayUnifiedOrder();
  266. $input->SetBody($name);
  267. $input->SetOut_trade_no($orderSn);
  268. $input->SetTotal_fee($totalFee * 100);
  269. $input->SetTime_start(date("YmdHis", $now));
  270. $input->SetAttach($attach);
  271. //设置订单有效期5分钟
  272. $input->SetTime_expire(date("YmdHis", $expireTime));
  273. $input->SetNotify_url(Yii::$app->params['hdHost'] . '/notice/wx-callback/');
  274. $input->SetTrade_type("JSAPI");
  275. //花卉宝代为申请的微信支付
  276. $merchantExtend = $this->sjExtend->attributes;
  277. if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
  278. $input->SetSub_openid($openId);
  279. } else {
  280. $input->SetOpenid($openId);
  281. }
  282. //小程序使用miniAppId
  283. if (httpUtil::isMiniProgram()) {
  284. $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
  285. }
  286. Yii::info('支付发起使用小程序信息' . json_encode($merchantExtend));
  287. $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
  288. $tools = new \JsApiPay();
  289. $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
  290. $newParams = json_decode($jsApiParameters, true);
  291. $newParams['orderId'] = $orderId;
  292. util::success($newParams);
  293. } elseif ($payWay == 1) {
  294. $extend = MerchantExtendService::getBySjId($sjId);
  295. if (isset($extend['alipayInit']) == false || $extend['alipayInit'] == 0) {
  296. util::fail('支付宝付款即将开通...');
  297. }
  298. $config = [
  299. //应用ID,您的APPID。
  300. 'app_id' => $extend['alipayPId'],
  301. //商户私钥,您的原始格式RSA私钥
  302. 'merchant_private_key' => $extend['alipayKey'],
  303. //异步通知地址
  304. 'notify_url' => Yii::$app->params['hdHost'] . "/notice/ali-callback",
  305. //同步跳转
  306. 'return_url' => "",
  307. //编码格式
  308. 'charset' => "UTF-8",
  309. //签名方式
  310. 'sign_type' => "RSA2",
  311. //支付宝网关
  312. 'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
  313. //支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
  314. 'alipay_public_key' => $extend['alipayPublicKey'],
  315. ];
  316. Yii::info(json_encode($config) . ' aplipay config');
  317. $alipayWap = Yii::getAlias("@vendor/alipayWap");
  318. require_once($alipayWap . '/wappay/service/AlipayTradeService.php');
  319. require_once($alipayWap . '/wappay/buildermodel/AlipayTradeWapPayContentBuilder.php');
  320. $totalFee = $order['realPrice'];
  321. $out_trade_no = $orderSn;//商户订单号,商户网站订单系统中唯一订单号,必填
  322. $subject = '购买商品';//订单名称,必填
  323. $total_amount = $totalFee;//付款金额,必填
  324. $body = '';//商品描述,可空
  325. $timeout_express = "1m";//超时时间
  326. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  327. $passBackParams = 'capitalType=' . $capitalType . '&couponId=' . $couponId . '&sjId=' . $sjId;//将流水类型、优惠卷传过去
  328. $passBackParams = urlencode($passBackParams);
  329. $payRequestBuilder = new \AlipayTradeWapPayContentBuilder();
  330. $payRequestBuilder->setBody($body);
  331. $payRequestBuilder->setSubject($subject);
  332. $payRequestBuilder->setOutTradeNo($out_trade_no);
  333. $payRequestBuilder->setTotalAmount($total_amount);
  334. $payRequestBuilder->setTimeExpress($timeout_express);
  335. //在异步通知时将该参数原样返回
  336. $payRequestBuilder->setPassbackParams($passBackParams);
  337. //同步通知
  338. $returnUrl = Yii::$app->params['mallDomain'] . "/#/pages/callback/success?account={$sjId}&shopId={$shopId}&orderSn={$orderSn}&totalPrice={$totalFee}&pageStatus=3&payDiscountPrice=0&payDiscountType=0";
  339. //异步通知
  340. $notifyUrl = Yii::$app->params['mallHost'] . "/notice/ali-callback";
  341. $payResponse = new \AlipayTradeService($config);
  342. $result = $payResponse->wapPay($payRequestBuilder, $returnUrl, $notifyUrl);
  343. //直接将支付宝的html返回给前端
  344. echo $result;
  345. } elseif ($payWay == 2) {
  346. //余额支付,验证支付密码是否正确
  347. $payPassword = isset($post['payPassword']) ? $post['payPassword'] : 0;
  348. $user = UserService::getUserInfo($this->adminId);
  349. UserService::validPayPassword($payPassword, $user);
  350. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  351. $callbackParams = [];
  352. $respond = xhPayToolService::balancePay($callbackParams, $orderSn, $actPrice, $capitalType, $couponId);
  353. $balance = isset($respond['balance']) ? $respond['balance'] : 0;
  354. util::success(['discountAmount' => $discountData['discountAmount'], 'discountType' => $discountData['discountType'], 'orderSn' => $orderSn, 'orderId' => $orderId, 'balance' => $balance]);
  355. } else {
  356. util::fail('无效的支付方式');
  357. }
  358. }
  359. //订单评价
  360. public function actionComment()
  361. {
  362. $post = Yii::$app->request->post();
  363. $id = $post['id'];
  364. $order = OrderService::getById($id);
  365. OrderService::valid($order, $this->shopId);
  366. if ($order['grade'] > 0) {
  367. util::fail('您已经评过了');
  368. }
  369. OrderService::comment($post);
  370. util::complete('提交成功');
  371. }
  372. //订单详情 ssh 2019.12.16
  373. public function actionDetail()
  374. {
  375. $id = Yii::$app->request->get('id', 0);
  376. $orderSn = Yii::$app->request->get('orderSn', '');
  377. $detail = [];
  378. if (!empty($id)) {
  379. $detail = OrderService::getOrderById($id);
  380. }
  381. if (!empty($orderSn)) {
  382. $detail = OrderService::getOrderBySn($orderSn);
  383. }
  384. OrderService::valid($detail, $this->shopId);
  385. //因前端未修改,这里先做一下兼容,好像打印时要调用到
  386. $detail['receiveProvince'] = $detail['province'] ?? '';
  387. $detail['receiveCity'] = $detail['city'] ?? '';
  388. $detail['receiveAddress'] = $detail['address'] ?? '';
  389. $detail['receiveFloor'] = $detail['floor'] ?? '';
  390. util::success($detail);
  391. }
  392. public function actionList()
  393. {
  394. $get = Yii::$app->request->get();
  395. $search = isset($get['search']) ? $get['search'] : '';
  396. $shopId = $this->shopId ?? 0;
  397. if (empty($shopId)) {
  398. //没有登录不显示数据
  399. util::success(['list' => [], 'moreData' => 0, 'shop' => [], 'totalNum' => 0, 'totalPage' => 0]);
  400. }
  401. $where = [];
  402. $where['shopId'] = $shopId;
  403. $status = $get['status'] ?? 0;
  404. if (!empty($status)) {
  405. $where['status'] = $get['status'];
  406. }
  407. if (!empty($search)) {
  408. if (stringUtil::isMobile($search)) {
  409. $where['bookMobile'] = $search;
  410. } else {
  411. $where['orderSn'] = $search;
  412. }
  413. }
  414. $searchTime = $get['searchTime'] ?? '';
  415. if (!empty($searchTime)) {
  416. $startTime = $get['startTime'] ?? '';
  417. $endTime = $get['endTime'] ?? '';
  418. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  419. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  420. }
  421. $list = OrderService::getOrderList($where);
  422. $list['shop'] = $this->shop->attributes ?? [];
  423. util::success($list);
  424. }
  425. //订单归类 ssh 2019.12.17
  426. public function actionClassify()
  427. {
  428. $post = Yii::$app->request->post();
  429. $id = isset($post['id']) ? $post['id'] : 0;
  430. $order = OrderService::getById($id);
  431. OrderService::valid($order, $this->shopId);
  432. $categoryId = isset($post['categoryId']) ? $post['categoryId'] : $post['categoryId'];
  433. $usageId = isset($post['usageId']) ? $post['usageId'] : $post['usageId'];
  434. OrderService::classify($id, $categoryId, $usageId);
  435. util::complete();
  436. }
  437. //更新配送单 ssh 2019.12.17
  438. public function actionUpdateSheet()
  439. {
  440. $post = Yii::$app->request->post();
  441. $id = isset($post['id']) ? $post['id'] : 0;
  442. unset($post['id']);
  443. $order = OrderService::getById($id);
  444. OrderService::valid($order, $this->shopId);
  445. OrderService::updateSheet($order, $post);
  446. util::complete('提交成功');
  447. }
  448. //商家收款与发货 ssh 2019.12.18
  449. public function actionGathering()
  450. {
  451. $post = Yii::$app->request->post();
  452. $price = isset($post['price']) && is_numeric($post['price']) ? $post['price'] : 0;
  453. $payWay = isset($post['payWay']) && is_numeric($post['payWay']) ? $post['payWay'] : 0;
  454. $userId = isset($post['userId']) ? $post['userId'] : 0;
  455. $userInfo = UserService::getById($userId);
  456. if (empty($userInfo) || $userInfo['sjId'] != $this->sjId) {
  457. util::fail('您选择的客户无效');
  458. }
  459. if ($price <= 0) {
  460. util::fail('请输入金额');
  461. }
  462. $post['prePrice'] = $price;
  463. $post['actPrice'] = $price;
  464. $post['payWay'] = $payWay;
  465. $post['sourceType'] = 1;
  466. $post['userId'] = $userId;
  467. $post['goodsNum'] = 1;
  468. $post['orderName'] = '商品';
  469. $shopId = MerchantService::getDefaultShopId($this->sj);
  470. $post['shopId'] = $shopId;
  471. $order = OrderService::addOrder($post);
  472. $id = $order['id'];
  473. $orderSn = $order['orderSn'];
  474. //流水类型列表
  475. $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
  476. $callbackParams = [];
  477. switch ($payWay) {
  478. case 0:
  479. xhPayToolService::wxPay($callbackParams, $orderSn, $price, $capitalType, 0);
  480. break;
  481. case 1:
  482. xhPayToolService::alipay($callbackParams, $orderSn, $price, $capitalType, 0, []);
  483. break;
  484. case 2:
  485. xhPayToolService::balancePay($callbackParams, $orderSn, $price, $capitalType, 0);
  486. break;
  487. default:
  488. util::fail('无效支付方式');
  489. }
  490. util::success($order);
  491. }
  492. //免发货管理 ssh 2020.1.6
  493. public function actionWithoutSend()
  494. {
  495. $id = Yii::$app->request->get('id');
  496. $order = OrderService::getById($id);
  497. OrderService::valid($order, $this->shopId);
  498. //配送流程变更
  499. $currentFlow = OrderSendClass::withoutSend($order);
  500. util::success(['currentFlow' => $currentFlow]);
  501. }
  502. //修改价格 ssh 2020.1.6
  503. public function actionUpdatePrice()
  504. {
  505. $id = Yii::$app->request->get('id');
  506. $price = Yii::$app->request->get('price', 1);
  507. $order = OrderService::getById($id);
  508. OrderService::valid($order, $this->shopId);
  509. if (isset($order['modPrice']) && $order['modPrice'] == 0) {
  510. util::fail('已发起支付,不能修改价格');
  511. }
  512. OrderService::updateById($id, ['actPrice' => $price]);
  513. util::complete('修改成功');
  514. }
  515. //配送单 ssh 2020.2.29
  516. public function actionGetDeliverDetail()
  517. {
  518. $id = Yii::$app->request->get('id', 0);
  519. $order = OrderService::getById($id);
  520. OrderService::valid($order, $this->shopId);
  521. $reachDate = isset($order['reachDate']) && !empty($order['reachDate']) ? $order['reachDate'] : '';
  522. $reachPeriodId = $order['reachPeriod'];
  523. $reachPeriodArr = [0 => '上午', 1 => '下午', 2 => '晚上'];
  524. $reachPeriod = isset($reachPeriodArr[$reachPeriodId]) ? $reachPeriodArr[$reachPeriodId] : '';
  525. $bookName = isset($order['bookName']) ? $order['bookName'] : '';
  526. $bookMobile = isset($order['bookMobile']) ? $order['bookMobile'] : '';
  527. if (isset($order['anonymity']) && $order['anonymity'] == 1) {
  528. $bookName = '--';
  529. $bookMobile = '--';
  530. }
  531. $data = [
  532. 'reachDate' => $reachDate . ' ' . $reachPeriod,
  533. 'orderSn' => $order['orderSn'],
  534. 'receiveUserName' => $order['receiveUserName'],
  535. 'receiveMobile' => $order['receiveMobile'],
  536. 'fullAddress' => $order['fullAddress'] . "(" . $order['showAddress'] . ")",
  537. 'cardInfo' => $order['cardInfo'],
  538. 'bookMobile' => $bookMobile,
  539. 'bookName' => $bookName,
  540. 'remark' => $order['remark'],
  541. 'sendNum' => $order['sendNum'],
  542. 'telephone' => 18030142050,
  543. 'printTime' => '',
  544. 'img' => '',
  545. ];
  546. util::success($data);
  547. }
  548. //运费计算 lqh 2021.4.12 暂反回固定
  549. public function actionFreight()
  550. {
  551. util::success(['sedCost' => 10]);
  552. }
  553. }