OrderController.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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\services\OrderService;
  8. use biz\saas\services\RegionService;
  9. use biz\user\services\UserService;
  10. use common\components\configDict;
  11. use common\services\xhPayToolService;
  12. use Yii;
  13. use common\components\util;
  14. use common\components\stringUtil;
  15. class OrderController extends BaseController
  16. {
  17. public function actionList()
  18. {
  19. $get = Yii::$app->request->get();
  20. $search = isset($get['search']) ? $get['search'] : '';
  21. $where = [];
  22. $where['merchantId'] = $this->merchantId;
  23. if (isset($get['status']) && $get['status'] != -1) {
  24. $where['status'] = $get['status'];
  25. }
  26. if (!empty($search)) {
  27. if (stringUtil::isMobile($search)) {
  28. $where['receiveMobile'] = $search;
  29. } else {
  30. $where['id'] = $search;
  31. }
  32. }
  33. $list = OrderService::getOrderList($where);
  34. $list['asset'] = MerchantAssetService::getByMerchantId($this->merchantId);
  35. util::success($list);
  36. }
  37. //订单详情 shish 2019.12.16
  38. public function actionDetail()
  39. {
  40. $id = Yii::$app->request->get('id');
  41. $detail = OrderService::getOrderById($id);
  42. util::success($detail);
  43. }
  44. //订单归类 shish 2019.12.17
  45. public function actionClassify()
  46. {
  47. $post = Yii::$app->request->post();
  48. $id = isset($post['id']) ? $post['id'] : 0;
  49. $order = OrderService::getById($id);
  50. OrderService::valid($order, $this->merchantId);
  51. $categoryId = isset($post['categoryId']) ? $post['categoryId'] : $post['categoryId'];
  52. $usageId = isset($post['usageId']) ? $post['usageId'] : $post['usageId'];
  53. OrderService::classify($id, $categoryId, $usageId);
  54. util::ok();
  55. }
  56. //更新配送单 shish 2019.12.17
  57. public function actionUpdateSheet()
  58. {
  59. $post = Yii::$app->request->post();
  60. $id = isset($post['id']) ? $post['id'] : 0;
  61. unset($post['id']);
  62. $order = OrderService::getById($id);
  63. OrderService::valid($order, $this->merchantId);
  64. OrderService::updateSheet($order, $post);
  65. util::ok('提交成功');
  66. }
  67. //商家收款与发货 shish 2019.12.18
  68. public function actionGathering()
  69. {
  70. $post = Yii::$app->request->post();
  71. $price = isset($post['price']) && is_numeric($post['price']) ? $post['price'] : 0;
  72. $payWay = isset($post['payWay']) && is_numeric($post['payWay']) ? $post['payWay'] : 0;
  73. $userId = isset($post['userId']) ? $post['userId'] : 0;
  74. $userInfo = UserService::getById($userId);
  75. if (empty($userInfo) || $userInfo['merchantId'] != $this->merchantId) {
  76. util::fail('您选择的客户无效');
  77. }
  78. if ($price <= 0) {
  79. util::fail('请输入金额');
  80. }
  81. $post['prePrice'] = $price;
  82. $post['actPrice'] = $price;
  83. $post['payWay'] = $payWay;
  84. $post['sourceType'] = 1;
  85. $post['userId'] = $userId;
  86. $post['goodsNum'] = 1;
  87. $post['orderName'] = '商品';
  88. $shopId = MerchantService::getDefaultShopId($this->merchant);
  89. $post['shopId'] = $shopId;
  90. $order = OrderService::addOrder($post);
  91. $id = $order['id'];
  92. $orderSn = $order['orderSn'];
  93. //流水类型列表
  94. $capitalTypeList = configDict::getConfig('capitalType');
  95. $capitalType = $capitalTypeList['xhOrder']['id'];
  96. switch ($payWay) {
  97. case 0:
  98. xhPayToolService::weixinPay($orderSn, $price, $capitalType, 0);
  99. break;
  100. case 1:
  101. xhPayToolService::alipay($orderSn, $price, $capitalType, 0, []);
  102. break;
  103. case 2:
  104. xhPayToolService::balancePay($orderSn, $price, $capitalType, 0);
  105. break;
  106. default:
  107. util::fail('无效支付方式');
  108. }
  109. util::success($order);
  110. }
  111. //免发货管理 shish 2020.1.6
  112. public function actionWithoutSend()
  113. {
  114. $id = Yii::$app->request->get('id');
  115. util::ok('操作成功');
  116. }
  117. //修改价格 shish 2020.1.6
  118. public function actionUpdatePrice()
  119. {
  120. $id = Yii::$app->request->get('id');
  121. $price = Yii::$app->request->get('price', 1);
  122. $order = OrderService::getById($id);
  123. OrderService::valid($order, $this->merchantId);
  124. if (isset($order['modPrice']) && $order['modPrice'] == 0) {
  125. util::fail('已发起支付,不能修改价格');
  126. }
  127. OrderService::updateById($id, ['actPrice' => $price]);
  128. util::ok('修改成功');
  129. }
  130. //下单要用到的相关信息 shish 2019.12.6
  131. public function actionOrderRelate()
  132. {
  133. $regionTree = RegionService::tree();
  134. $shop = ShopService::getDefaultShop($this->merchant);
  135. $freight = MerchantExtendService::getFreight($this->merchantExtend);
  136. $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
  137. $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'txMapKey' => $mapKey, 'merchant' => $this->merchant];
  138. util::success($out);
  139. }
  140. }