| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- <?php
- namespace addons\Happiness\agent\controllers;
- use addons\Happiness\common\enums\HappinessEnum;
- use addons\Happiness\common\models\HappinessMoveItem;
- use addons\Happiness\common\models\HappinessStore;
- use addons\Happiness\common\service\MoveService;
- use common\enums\StatusEnum;
- use Yii;
- use Exception;
- class MoveController extends BaseController
- {
- public function actionIndex()
- {
- if(Yii::$app->request->isAjax)
- {
- if(Yii::$app->request->isGet)
- {
- $data = Yii::$app->request->get();
- $where[]=['=','yo.status',StatusEnum::ENABLED];
- $where[]=['=','yo.mall_id',$this->mall_id];
- //or条件
- $where[] = ['or', ['in', 'st.city_id', $this->city_ids], ['in', 'st.district_id', $this->district_ids],['in', 'st.province_id', $this->province_ids]];
- if(!empty($data['keyword']))
- {
- $where[] = ['or', ['=', 'st.id', $data['keyword']], ['like', 'st.store_name',
- $data['keyword']]];
- }
- if($data['status']!='all')
- {
- $where[] = ['=', 'yo.order_status', $data['status']];
- }
- $with = [
- 'mallGood'=>function ($query) {
- $query->select('id,goods_name,cover_pic');
- },
- 'giveStore'=>function ($query) {
- $query->select('id,store_name,logo_img');
- }
- ];
- $join = [['LEFT JOIN',
- HappinessStore::tableName(). ' as st', "yo.store_id = st.id"]];
- $params = [
- 'select' => 'yo.*,st.city_id,st.district_id,st.store_name,st.logo_img',
- 'alias' => 'yo',
- 'where' =>$where,
- 'with' => $with,
- 'join' => $join,
- 'order' => 'id desc',
- ];
- $list=HappinessMoveItem::listPage($params);
- if($list===false)
- {
- return $this->error(HappinessMoveItem::getStaticError());
- }
- foreach ($list['list'] as &$item)
- {
- $item['goods_image'] = $item['mallGood']['cover_pic'];
- $item['goods_name'] = $item['mallGood']['goods_name'];
- $item['order_status_text'] = HappinessEnum::getMoveStatusMap()[$item['order_status']];
- }
- return $this->success('获取成功',$list);
- }
- }
- return $this->render('index');
- }
- public function actionMove()
- {
- if(Yii::$app->request->isAjax)
- {
- if(Yii::$app->request->isGet)
- {
- $id = Yii::$app->request->get('id');
- $model = HappinessMoveItem::find()->with(['goods.attr','goods.goods'])->where(['id'=>$id,
- 'status'=>StatusEnum::ENABLED])->asArray()->one();
- if(!$model)
- {
- return $this->error('数据不存在');
- }
- $goods_list=$model['goods'];
- //调货小店
- $where = ['and'];
- $where[] = ['or',
- ['in', 'city_id', $this->city_ids],
- ['in', 'district_id', $this->district_ids]
- ];
- $where[] = ['=', 'status', StatusEnum::ENABLED];
- $where[] = ['=', 'mall_id', $this->mall_id];
- $store_list = HappinessStore::find()
- ->select('id,store_name,logo_img')
- ->where($where)
- ->asArray()
- ->all();
- return $this->success('获取成功',compact('store_list','goods_list'));
- }
- if(Yii::$app->request->isPost)
- {
- $data = Yii::$app->request->post();
- if(empty($data))
- {
- return $this->error('参数错误');
- }
- $id=$data['id'];
- $has=HappinessMoveItem::find()->where(['id'=>$id])->one();
- if(!$has)
- {
- return $this->error('数据不存在');
- }
- if($has['order_status']!=0)
- {
- return $this->error('调货单已处理');
- }
- $store_id=$data['store_id'];
- $service=new MoveService(['mall_id'=>$this->mall_id,'store_id'=>$store_id,
- 'user_id'=>$this->admin->user_id]);
- $res=$service->auditMove($data);
- if($res===false)
- {
- return $this->error($service->getError());
- }
- if($data['audit_status']==0)
- {
- return $this->success('拒绝调货');
- }
- return $this->success('调货成功');
- }
- }
- }
- }
|