OrderController.php 3.3 KB

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