OrderController.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace addons\Seckill\backend\controllers;
  3. use addons\Seckill\common\enums\SeckillEnum;
  4. use common\enums\StatusEnum;
  5. use common\models\order\Order;
  6. use common\models\user\User;
  7. use Yii;
  8. use addons\Seckill\common\models\SeckillActivity;
  9. /**
  10. * 订单控制器
  11. *
  12. * Class OrderController
  13. * @package addons\Seckill\backend\controllers
  14. */
  15. class OrderController extends BaseController
  16. {
  17. public $enableCsrfValidation = false;
  18. /**
  19. * 首页
  20. *
  21. * @return string
  22. */
  23. public function actionIndex()
  24. {
  25. return $this->render('/order/index');
  26. }
  27. public function actionList()
  28. {
  29. try {
  30. $activity_id = \Yii::$app->request->get('activity_id') ?? 0;
  31. $order_no = \Yii::$app->request->get('order_no') ?? '';
  32. $mobile = \Yii::$app->request->get('mobile') ?? '';
  33. $user_id = \Yii::$app->request->get('user_id') ?? '';
  34. $begin = \Yii::$app->request->get('begin') ?? '';
  35. $end = \Yii::$app->request->get('end') ?? '';
  36. $page = \Yii::$app->request->get('page', 1);
  37. $limit = \Yii::$app->request->get('limit', $this->pageSize);
  38. $where[] = ['and', ['mall_id' => $this->mall_id], ['!=', 'status', StatusEnum::DELETE],['=', 'order_source', SeckillEnum::ADDONS_NAME]];
  39. if($activity_id){
  40. $where[] = ['=', 'extra_info', 'seckill_activity_'.$activity_id];
  41. }
  42. if($order_no){
  43. $where[] = ['=', 'order_no', $order_no];
  44. }
  45. if($user_id){
  46. $where[] = ['=', 'user_id', $user_id];
  47. }
  48. if($mobile){
  49. $uids = User::find()->select('id')->where(['like','mobile',$mobile.'%',false])->column();
  50. !empty($uids) && $where[] = ['in', 'user_id', $uids];
  51. }
  52. ($begin ?? false) && $where[] = ['>=', 'created_at', strtotime($begin)];
  53. ($end ?? false) && $where[] = ['<=', 'created_at', strtotime($end)];
  54. $with = ['base_user', 'detail'];
  55. $order = "id desc";
  56. $params = compact('where', 'with', 'order');
  57. $page_data = Order::listPage($params, false, true);
  58. $extra_info = array_column($page_data['list'],'extra_info');
  59. $activity_ids = [];
  60. foreach($extra_info as $value){
  61. $id = str_replace('seckill_activity_','',$value);
  62. $id && $activity_ids[] = $id;
  63. }
  64. $activity_ids = array_unique($activity_ids);
  65. //查询活动
  66. $activity_list = SeckillActivity::find()->where(['id' => $activity_ids])->select('id,title,price')->asArray()->all();
  67. $activity_list = array_column($activity_list,null,'id');
  68. foreach($page_data['list'] as $key =>$value){
  69. $activity_id = str_replace('seckill_activity_','',$value['extra_info']);
  70. $value['activity_title'] = $activity_list[$activity_id]['title'] ?? '';
  71. $value['activity_price'] = $activity_list[$activity_id]['price'] ?? 0;
  72. $page_data['list'][$key] = $value;
  73. }
  74. return $this->success('请求成功', $page_data);
  75. } catch (\Exception $exception) {
  76. return $this->error($exception->getMessage());
  77. }
  78. }
  79. }