OrderController.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. class OrderController extends BaseController
  17. {
  18. public function actionList()
  19. {
  20. $get = Yii::$app->request->get();
  21. $search = isset($get['search']) ? $get['search'] : '';
  22. $where = [];
  23. $where['merchantId'] = $this->merchantId;
  24. if (isset($get['status']) && $get['status'] != -1) {
  25. $where['status'] = $get['status'];
  26. }
  27. if (!empty($search)) {
  28. if (stringUtil::isMobile($search)) {
  29. $where['receiveMobile'] = $search;
  30. } else {
  31. $where['id'] = $search;
  32. }
  33. }
  34. $list = OrderService::getOrderList($where);
  35. $list['asset'] = MerchantAssetService::getByMerchantId($this->merchantId);
  36. util::success($list);
  37. }
  38. //订单详情 shish 2019.12.16
  39. public function actionDetail()
  40. {
  41. $id = Yii::$app->request->get('id');
  42. $detail = OrderService::getOrderById($id);
  43. util::success($detail);
  44. }
  45. //订单归类 shish 2019.12.17
  46. public function actionClassify()
  47. {
  48. $post = Yii::$app->request->post();
  49. $id = isset($post['id']) ? $post['id'] : 0;
  50. $order = OrderService::getById($id);
  51. OrderService::valid($order, $this->merchantId);
  52. $categoryId = isset($post['categoryId']) ? $post['categoryId'] : $post['categoryId'];
  53. $usageId = isset($post['usageId']) ? $post['usageId'] : $post['usageId'];
  54. OrderService::classify($id, $categoryId, $usageId);
  55. util::complete();
  56. }
  57. //更新配送单 shish 2019.12.17
  58. public function actionUpdateSheet()
  59. {
  60. $post = Yii::$app->request->post();
  61. $id = isset($post['id']) ? $post['id'] : 0;
  62. unset($post['id']);
  63. $order = OrderService::getById($id);
  64. OrderService::valid($order, $this->merchantId);
  65. OrderService::updateSheet($order, $post);
  66. util::complete('提交成功');
  67. }
  68. //商家收款与发货 shish 2019.12.18
  69. public function actionGathering()
  70. {
  71. $post = Yii::$app->request->post();
  72. $price = isset($post['price']) && is_numeric($post['price']) ? $post['price'] : 0;
  73. $payWay = isset($post['payWay']) && is_numeric($post['payWay']) ? $post['payWay'] : 0;
  74. $userId = isset($post['userId']) ? $post['userId'] : 0;
  75. $userInfo = UserService::getById($userId);
  76. if (empty($userInfo) || $userInfo['merchantId'] != $this->merchantId) {
  77. util::fail('您选择的客户无效');
  78. }
  79. if ($price <= 0) {
  80. util::fail('请输入金额');
  81. }
  82. $post['prePrice'] = $price;
  83. $post['actPrice'] = $price;
  84. $post['payWay'] = $payWay;
  85. $post['sourceType'] = 1;
  86. $post['userId'] = $userId;
  87. $post['goodsNum'] = 1;
  88. $post['orderName'] = '商品';
  89. $shopId = MerchantService::getDefaultShopId($this->merchant);
  90. $post['shopId'] = $shopId;
  91. $order = OrderService::addOrder($post);
  92. $id = $order['id'];
  93. $orderSn = $order['orderSn'];
  94. //流水类型列表
  95. $capitalTypeList = configDict::getConfig('capitalType');
  96. $capitalType = $capitalTypeList['xhOrder']['id'];
  97. $callbackParams = [];
  98. switch ($payWay) {
  99. case 0:
  100. xhPayToolService::weixinPay($callbackParams, $orderSn, $price, $capitalType, 0);
  101. break;
  102. case 1:
  103. xhPayToolService::alipay($callbackParams, $orderSn, $price, $capitalType, 0, []);
  104. break;
  105. case 2:
  106. xhPayToolService::balancePay($callbackParams, $orderSn, $price, $capitalType, 0);
  107. break;
  108. default:
  109. util::fail('无效支付方式');
  110. }
  111. util::success($order);
  112. }
  113. //免发货管理 shish 2020.1.6
  114. public function actionWithoutSend()
  115. {
  116. $id = Yii::$app->request->get('id');
  117. $order = OrderService::getById($id);
  118. OrderService::valid($order, $this->merchantId);
  119. //配送流程变更
  120. $currentFlow = OrderSendClass::withoutSend($order);
  121. util::success(['currentFlow' => $currentFlow]);
  122. }
  123. //修改价格 shish 2020.1.6
  124. public function actionUpdatePrice()
  125. {
  126. $id = Yii::$app->request->get('id');
  127. $price = Yii::$app->request->get('price', 1);
  128. $order = OrderService::getById($id);
  129. OrderService::valid($order, $this->merchantId);
  130. if (isset($order['modPrice']) && $order['modPrice'] == 0) {
  131. util::fail('已发起支付,不能修改价格');
  132. }
  133. OrderService::updateById($id, ['actPrice' => $price]);
  134. util::complete('修改成功');
  135. }
  136. //下单要用到的相关信息 shish 2019.12.6
  137. public function actionOrderRelate()
  138. {
  139. $regionTree = RegionService::tree();
  140. $shop = ShopService::getDefaultShop($this->merchant);
  141. $freight = MerchantExtendService::getFreight($this->merchantExtend);
  142. $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
  143. $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'txMapKey' => $mapKey, 'merchant' => $this->merchant];
  144. util::success($out);
  145. }
  146. //配送单 shish 2020.2.29
  147. public function actionGetDeliverDetail()
  148. {
  149. $id = Yii::$app->request->get('id', 0);
  150. $order = OrderService::getById($id);
  151. OrderService::valid($order, $this->merchantId);
  152. $data = [
  153. 'reachDate' => '2020-2-29 上午',
  154. 'orderSn' => '200225174930123621254374243185',
  155. 'receiveUserName' => '阿梅',
  156. 'receiveMobile' => '15280215347',
  157. 'receiveFullAddress' => '福建省厦门市思明区上湖社126号206室',
  158. 'cardInfo' => '我爱你,宝贝',
  159. 'bookMobile' => '17189513228',
  160. 'bookName' => '阿宽',
  161. 'remark' => '最迟下午要帮送,亲自给本人',
  162. 'sendNum' => 653,
  163. 'telephone' => 17189513228,
  164. 'printTime' => '2020-3-7 18:09',
  165. 'img' => 'http://img.huaml.com/example/goods/1.jpg',
  166. ];
  167. util::success($data);
  168. }
  169. }