OrderController.php 3.9 KB

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