request->isAjax) { if (\Yii::$app->request->isGet) { $page = \Yii::$app->request->get('page', 1); $limit = \Yii::$app->request->get('limit', $this->pageSize); $start_time=\Yii::$app->request->get('start_time'); $end_time=\Yii::$app->request->get('end_time'); $status=\Yii::$app->request->get('status'); $wheres = []; $wheres[]=['=', 'status', StatusEnum::ENABLED]; $wheres[]=['=', 'mall_id', $this->mall_id]; $wheres[]=['=', 'store_id', $this->store_id]; if(!empty($start_time)) { $wheres[] = ['>=','created_at', strtotime($start_time)]; } if(!empty($end_time)) { $wheres[] = ['<=','created_at', strtotime($end_time)+86400]; } if(!empty($status)) { $wheres[] = ['=','order_status', $status]; } $params = [ 'select' => '*', 'where' => $wheres, 'order' => 'created_at desc', 'page' => $page, 'limit' => $limit, 'with' => [ 'store'=>function ($query) { $query->select('id,store_name'); } ], ]; $list = HappinessVoucherOrder::listPage($params); if (false === $list) { return $this->error(HappinessVoucherOrder::getStaticError()); } if(!empty($list['list'])) { foreach ($list['list'] as &$item) { $item['order_status_text'] = HappinessVoucherEnum::getOrderStatusMap()[$item['order_status']]; $item['order_no']=$item['order_no'].' '; } } return $this->success('操作成功',$list); } } return $this->render('index'); } public function actionConfirm() { if(Yii::$app->request->isAjax) { $id = \Yii::$app->request->post('id'); $model = HappinessVoucherOrder::find()->where(['id'=>$id,'mall_id'=>$this->mall_id,'store_id'=>$this->store_id,'status'=>StatusEnum::ENABLED])->one(); if(!$model) { return $this->error('订单不存在'); } $service=new VoucherService(['mall_id'=>$this->mall_id,'store_id'=>$this->store_id]); $result = $service->confirm($model); if($result==false) { return $this->error($service->getError()); } return $this->success('操作成功'); } } public function actionExpress() { if(Yii::$app->request->isAjax) { if (\Yii::$app->request->isGet) { $id = Yii::$app->request->get('id'); $model = HappinessVoucherOrder::find()->where(['id'=>$id,'mall_id'=>$this->mall_id,'store_id'=>$this->store_id,'status'=>StatusEnum::ENABLED])->one(); if(!$model) return $this->error('订单不存在'); $list = HappinessVoucherExpress::find()->with(['goods'])->where(['order_id' => $id,'mall_id' => $this->mall_id]) ->asArray()->all(); $goods_ids=[]; $goods_attr_ids=[]; foreach ($list as &$item) { foreach ($item['goods'] as &$goods) { $goods_ids[]=$goods['goods_id']; $goods_attr_ids[]=$goods['attr_id']; } } $goods_list=Goods::find()->where(['id' => $goods_ids,'mall_id' => $this->mall_id]) ->asArray() ->indexBy('id') ->all(); $goods_attr_list=GoodsAttr::find()->where(['id' => $goods_attr_ids]) ->asArray() ->indexBy('id') ->all(); $voucherGoods=HappinessVoucherGoods::find()->where(['order_id' => $id,'mall_id' => $this->mall_id]) ->asArray() ->indexBy('attr_id') ->all(); foreach ($list as &$item) { foreach ($item['goods'] as &$goods) { $goods['buy_num']=$voucherGoods[$goods['attr_id']]['num']; $goods['goods_name']=$goods_list[$goods['goods_id']]['goods_name']; $goods['goods_attr_name']=$goods_attr_list[$goods['attr_id']]['name']; $goods['cover_pic']=empty($goods_attr_list[$goods['attr_id']]['pic_url'])?$goods_list[$goods['goods_id']]['cover_pic']:$goods_attr_list[$goods['attr_id']]['pic_url']; } } return $this->success('操作成功',$list); } } } public function actionDetail() { if(Yii::$app->request->isAjax) { if (\Yii::$app->request->isGet) { $id = Yii::$app->request->get('id'); $model = HappinessVoucherOrder::find()->with(['goods'])->where(['id' => $id,'mall_id' => $this->mall_id,'store_id'=>$this->store_id]) ->asArray() ->one(); if(!$model) { return $this->error('数据不存在'); } $goods_attr_ids=array_column($model['goods'],'attr_id'); $goods_ids=array_column($model['goods'],'goods_id'); $goods_list=Goods::find()->where(['id' => $goods_ids,'mall_id' => $this->mall_id]) ->asArray() ->indexBy('id') ->all(); $goods_attr_list=GoodsAttr::find()->where(['id' => $goods_attr_ids]) ->asArray() ->indexBy('id') ->all(); foreach ($model['goods'] as &$item) { $item['goods_name']=$goods_list[$item['goods_id']]['goods_name']; $item['goods_attr_name']=$goods_attr_list[$item['attr_id']]['name']; $item['cover_pic']=empty($goods_attr_list[$item['attr_id']]['pic_url'])?$goods_list[$item['goods_id']]['cover_pic']:$goods_attr_list[$item['attr_id']]['pic_url']; } return $this->success('操作成功',$model); } } } }