OrderController.php 25 KB

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