OrderController.php 25 KB

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