request->isAjax) { if (\Yii::$app->request->isGet) { $page = \Yii::$app->request->get('page', 1); $limit = \Yii::$app->request->get('limit', $this->pageSize); $store_keyword=\Yii::$app->request->get('store_keyword'); $start_time=\Yii::$app->request->get('start_time'); $end_time=\Yii::$app->request->get('end_time'); $wheres = []; $wheres[]=['=', 'status', StatusEnum::ENABLED]; $wheres[]=['=', 'mall_id', $this->mall_id]; if(!empty($store_keyword)) { $store_where=[ 'or', ['=', 'id', $store_keyword], ['like', 'store_name', $store_keyword] ]; $store_ids=HappinessStore::find()->where(['status' => StatusEnum::ENABLED,'mall_id' => $this->mall_id])->andWhere($store_where) ->select('id')->column()??[]; $wheres[] = ['in','store_id' ,$store_ids]; } if(!empty($start_time)) { $wheres[] = ['>=','created_at', strtotime($start_time)]; } if(!empty($end_time)) { $wheres[] = ['<=','created_at', strtotime($end_time)+86400]; } $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 actionSwitchStatus() { $id = Yii::$app->request->post('id'); $status = Yii::$app->request->post('status'); $model = HappinessVoucherOrder::findOne(['id' => $id,'mall_id' => $this->mall_id]); $remark = Yii::$app->request->post('remark'); if (!$model) { return $this->error('数据不存在'); } if ($model->order_status==HappinessVoucherEnum::ORDER_STATUS_IS_AUDIT) { return $this->error('已审核过了,禁止操作'); } if ($model->order_status!=HappinessVoucherEnum::ORDER_STATUS_NO_AUDIT) { return $this->error('非待审核状态,禁止操作'); } if($status==0) { $order_status=HappinessVoucherEnum::ORDER_STATUS_REFUSE; } else { $order_status=HappinessVoucherEnum::ORDER_STATUS_IS_AUDIT; } $model->order_status = $order_status; $model->remark = $remark; if ($model->save()) { $service=new VoucherService(); if($order_status==HappinessVoucherEnum::ORDER_STATUS_REFUSE) { $res=$service->returnVoucher($model->id); if($res===false) { return $this->error($service->getError()); } } return $this->success('操作成功'); } return $this->error('操作失败'); } //发货 public function actionSend() { if(Yii::$app->request->isAjax) { if (\Yii::$app->request->isPost) { $post=Yii::$app->request->post(); $service=new VoucherService(['mall_id' => $this->mall_id]); $res=$service->send($post); if($res===false) { return $this->error($service->getError()); } return $this->success('操作成功'); } if (\Yii::$app->request->isGet) { $id = Yii::$app->request->get('id'); $model = HappinessVoucherOrder::findOne(['id' => $id,'mall_id' => $this->mall_id]); } } } public function actionExpress() { if(Yii::$app->request->isAjax) { if (\Yii::$app->request->isGet) { $id = Yii::$app->request->get('id'); $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]) ->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); } } } }