OrderController.php 28 KB

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