OrderController.php 4.5 KB

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