| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php
- namespace addons\Seckill\backend\controllers;
- use addons\Seckill\common\enums\SeckillEnum;
- use common\enums\StatusEnum;
- use common\models\order\Order;
- use common\models\user\User;
- use Yii;
- use addons\Seckill\common\models\SeckillActivity;
- /**
- * 订单控制器
- *
- * Class OrderController
- * @package addons\Seckill\backend\controllers
- */
- class OrderController extends BaseController
- {
- public $enableCsrfValidation = false;
- /**
- * 首页
- *
- * @return string
- */
- public function actionIndex()
- {
- return $this->render('/order/index');
- }
- public function actionList()
- {
- try {
- $activity_id = \Yii::$app->request->get('activity_id') ?? 0;
- $order_no = \Yii::$app->request->get('order_no') ?? '';
- $mobile = \Yii::$app->request->get('mobile') ?? '';
- $user_id = \Yii::$app->request->get('user_id') ?? '';
- $begin = \Yii::$app->request->get('begin') ?? '';
- $end = \Yii::$app->request->get('end') ?? '';
- $page = \Yii::$app->request->get('page', 1);
- $limit = \Yii::$app->request->get('limit', $this->pageSize);
- $where[] = ['and', ['mall_id' => $this->mall_id], ['!=', 'status', StatusEnum::DELETE],['=', 'order_source', SeckillEnum::ADDONS_NAME]];
- if($activity_id){
- $where[] = ['=', 'extra_info', 'seckill_activity_'.$activity_id];
- }
- if($order_no){
- $where[] = ['=', 'order_no', $order_no];
- }
- if($user_id){
- $where[] = ['=', 'user_id', $user_id];
- }
- if($mobile){
- $uids = User::find()->select('id')->where(['like','mobile',$mobile.'%',false])->column();
- !empty($uids) && $where[] = ['in', 'user_id', $uids];
- }
- ($begin ?? false) && $where[] = ['>=', 'created_at', strtotime($begin)];
- ($end ?? false) && $where[] = ['<=', 'created_at', strtotime($end)];
- $with = ['base_user', 'detail'];
- $order = "id desc";
- $params = compact('where', 'with', 'order');
- $page_data = Order::listPage($params, false, true);
- $extra_info = array_column($page_data['list'],'extra_info');
- $activity_ids = [];
- foreach($extra_info as $value){
- $id = str_replace('seckill_activity_','',$value);
- $id && $activity_ids[] = $id;
- }
- $activity_ids = array_unique($activity_ids);
- //查询活动
- $activity_list = SeckillActivity::find()->where(['id' => $activity_ids])->select('id,title,price')->asArray()->all();
- $activity_list = array_column($activity_list,null,'id');
- foreach($page_data['list'] as $key =>$value){
- $activity_id = str_replace('seckill_activity_','',$value['extra_info']);
- $value['activity_title'] = $activity_list[$activity_id]['title'] ?? '';
- $value['activity_price'] = $activity_list[$activity_id]['price'] ?? 0;
- $page_data['list'][$key] = $value;
- }
- return $this->success('请求成功', $page_data);
- } catch (\Exception $exception) {
- return $this->error($exception->getMessage());
- }
- }
- }
|