OrderController.php 27 KB

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