OrderController.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. switch ($payWay) {
  98. case 0:
  99. xhPayToolService::weixinPay($orderSn, $price, $capitalType, 0);
  100. break;
  101. case 1:
  102. xhPayToolService::alipay($orderSn, $price, $capitalType, 0, []);
  103. break;
  104. case 2:
  105. xhPayToolService::balancePay($orderSn, $price, $capitalType, 0);
  106. break;
  107. default:
  108. util::fail('无效支付方式');
  109. }
  110. util::success($order);
  111. }
  112. //免发货管理 shish 2020.1.6
  113. public function actionWithoutSend()
  114. {
  115. $id = Yii::$app->request->get('id');
  116. $order = OrderService::getById($id);
  117. OrderService::valid($order, $this->merchantId);
  118. //配送流程变更
  119. $currentFlow = OrderSendClass::withoutSend($order);
  120. util::success(['currentFlow' => $currentFlow]);
  121. }
  122. //修改价格 shish 2020.1.6
  123. public function actionUpdatePrice()
  124. {
  125. $id = Yii::$app->request->get('id');
  126. $price = Yii::$app->request->get('price', 1);
  127. $order = OrderService::getById($id);
  128. OrderService::valid($order, $this->merchantId);
  129. if (isset($order['modPrice']) && $order['modPrice'] == 0) {
  130. util::fail('已发起支付,不能修改价格');
  131. }
  132. OrderService::updateById($id, ['actPrice' => $price]);
  133. util::complete('修改成功');
  134. }
  135. //下单要用到的相关信息 shish 2019.12.6
  136. public function actionOrderRelate()
  137. {
  138. $regionTree = RegionService::tree();
  139. $shop = ShopService::getDefaultShop($this->merchant);
  140. $freight = MerchantExtendService::getFreight($this->merchantExtend);
  141. $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
  142. $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'txMapKey' => $mapKey, 'merchant' => $this->merchant];
  143. util::success($out);
  144. }
  145. //配送单 shish 2020.2.29
  146. public function actionGetDeliverDetail()
  147. {
  148. $id = Yii::$app->request->get('id', 0);
  149. $order = OrderService::getById($id);
  150. OrderService::valid($order, $this->merchantId);
  151. $data = [
  152. 'reachDate' => '2020-2-29 上午',
  153. 'orderSn' => '200225174930123621254374243185',
  154. 'receiveUserName' => '阿梅',
  155. 'receiveMobile' => '15280215347',
  156. 'receiveFullAddress' => '福建省厦门市思明区上湖社126号206室',
  157. 'cardInfo' => '我爱你,宝贝',
  158. 'bookMobile' => '17189513228',
  159. 'bookName' => '阿宽',
  160. 'remark' => '最迟下午要帮送,亲自给本人',
  161. 'sendNum' => 653,
  162. 'telephone' => 17189513228,
  163. 'printTime' => '2020-3-7 18:09',
  164. 'img' => 'http://img.huaml.com/example/goods/1.jpg',
  165. ];
  166. util::success($data);
  167. }
  168. }