| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- <?php
- namespace addons\Happiness\client\controllers;
- use addons\Happiness\common\enums\HappinessPensionEnum;
- use addons\Happiness\common\enums\HappinessVoucherEnum;
- use addons\Happiness\common\models\HappinessPension;
- use addons\Happiness\common\models\HappinessStore;
- use addons\Happiness\common\models\HappinessVoucherExpress;
- use addons\Happiness\common\models\HappinessVoucherExpressGoods;
- use addons\Happiness\common\models\HappinessVoucherGoods;
- use addons\Happiness\common\models\HappinessVoucherOrder;
- use addons\Happiness\common\service\VoucherService;
- use common\enums\StatusEnum;
- use common\models\goods\Goods;
- use common\models\goods\GoodsAttr;
- use Yii;
- class VoucherOrderController extends BaseController
- {
- public function actionIndex()
- {
- if(Yii::$app->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);
- }
- }
- }
- }
|