OrderController.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. namespace business\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. class OrderController extends BaseController
  18. {
  19. public function actionList()
  20. {
  21. $get = Yii::$app->request->get();
  22. $search = isset($get['search']) ? $get['search'] : '';
  23. $where = [];
  24. $where['merchantId'] = $this->merchantId;
  25. if (isset($get['status']) && $get['status'] != -1) {
  26. $where['status'] = $get['status'];
  27. }
  28. if (!empty($search)) {
  29. if (stringUtil::isMobile($search)) {
  30. $where['receiveMobile'] = $search;
  31. } else {
  32. $where['id'] = $search;
  33. }
  34. }
  35. $list = OrderService::getOrderList($where);
  36. $list['asset'] = MerchantAssetService::getByMerchantId($this->merchantId);
  37. util::success($list);
  38. }
  39. //订单详情 shish 2019.12.16
  40. public function actionDetail()
  41. {
  42. $id = Yii::$app->request->get('id');
  43. $detail = OrderService::getOrderById($id);
  44. util::success($detail);
  45. }
  46. //订单归类 shish 2019.12.17
  47. public function actionClassify()
  48. {
  49. $post = Yii::$app->request->post();
  50. $id = isset($post['id']) ? $post['id'] : 0;
  51. $order = OrderService::getById($id);
  52. OrderService::valid($order, $this->merchantId);
  53. $categoryId = isset($post['categoryId']) ? $post['categoryId'] : $post['categoryId'];
  54. $usageId = isset($post['usageId']) ? $post['usageId'] : $post['usageId'];
  55. OrderService::classify($id, $categoryId, $usageId);
  56. util::complete();
  57. }
  58. //更新配送单 shish 2019.12.17
  59. public function actionUpdateSheet()
  60. {
  61. $post = Yii::$app->request->post();
  62. $id = isset($post['id']) ? $post['id'] : 0;
  63. unset($post['id']);
  64. $order = OrderService::getById($id);
  65. OrderService::valid($order, $this->merchantId);
  66. OrderService::updateSheet($order, $post);
  67. util::complete('提交成功');
  68. }
  69. //商家收款与发货 shish 2019.12.18
  70. public function actionGathering()
  71. {
  72. $post = Yii::$app->request->post();
  73. $price = isset($post['price']) && is_numeric($post['price']) ? $post['price'] : 0;
  74. $payWay = isset($post['payWay']) && is_numeric($post['payWay']) ? $post['payWay'] : 0;
  75. $userId = isset($post['userId']) ? $post['userId'] : 0;
  76. $userInfo = UserService::getById($userId);
  77. if (empty($userInfo) || $userInfo['merchantId'] != $this->merchantId) {
  78. util::fail('您选择的客户无效');
  79. }
  80. if ($price <= 0) {
  81. util::fail('请输入金额');
  82. }
  83. $post['prePrice'] = $price;
  84. $post['actPrice'] = $price;
  85. $post['payWay'] = $payWay;
  86. $post['sourceType'] = 1;
  87. $post['userId'] = $userId;
  88. $post['goodsNum'] = 1;
  89. $post['orderName'] = '商品';
  90. $shopId = MerchantService::getDefaultShopId($this->merchant);
  91. $post['shopId'] = $shopId;
  92. $order = OrderService::addOrder($post);
  93. $id = $order['id'];
  94. $orderSn = $order['orderSn'];
  95. //流水类型列表
  96. $capitalTypeList = configDict::getConfig('capitalType');
  97. $capitalType = $capitalTypeList['xhOrder']['id'];
  98. switch ($payWay) {
  99. case 0:
  100. xhPayToolService::weixinPay($orderSn, $price, $capitalType, 0);
  101. break;
  102. case 1:
  103. xhPayToolService::alipay($orderSn, $price, $capitalType, 0, []);
  104. break;
  105. case 2:
  106. xhPayToolService::balancePay($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 actionDeliver()
  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. }