shop_id=$this->storeId?:Store::getMainStore($this->wqData['uniacid'])['id']; $this->shop_id=$this->shop_id?:0; $power=Power::getPayPower($this->wqData['uniacid'],'rollBag'); if(!$power){ echo json_encode(['code'=>2,'msg'=>'暂无权限']);die; } } //券包活动列表 public function actionRollBagList(){ $result=axios_request(); $storeId=$result['storeId']?:$this->shop_id; $page=$result['page']?:1; $num=($page-1)*10; $limit=10; $table=(new \yii\db\Query()) ->from('{{%ybwm_roll_bag}}') ->select('salesNum,id,name,from_unixtime(createdAt) createdAt,display,from_unixtime(startTime) startTime,from_unixtime(endTime) endTime,price,money,stock') ->where(['deleteAt'=>0,'uniacid'=>$this->wqData['uniacid'],'storeId'=>$storeId]); $list=$table->offset($num) ->limit($limit)->orderBy('id desc')->all(); $count=$table->count(); // for($i=0;$ifrom('{{%ybwm_roll_bag_order}}') // ->where('bagId=:bagId AND state=2',[':bagId'=>$list[$i]['id']])->count(); // } return $this->result(1, '成功',$list,$count); } //保存券包 public function actionSaveRollBag(){ $result=axios_request(); $request = Yii::$app->request; $storeId=$result['storeId']?:$this->shop_id; if($request->isGet){ $info=(new \yii\db\Query()) ->from('{{%ybwm_roll_bag}}') ->where('id=:id',[':id'=>$result['id']])->one(); $info['coupon']=json_decode($info['coupon'],true); $info['media']=json_decode($info['media'],true); $info['startTime']=date("Y-m-d H:i:s",$info['startTime']); $info['endTime']=date("Y-m-d H:i:s",$info['endTime']); return $this->result(1, '成功',$info); } if(!$result['name']){ return $this->result(2,'活动名称不能为空!'); } $num=0; for($i=0;$ifrom('{{%ybwm_roll_bag}}') ->where('id!=:id AND deleteAt=0 AND uniacid=:uniacid AND storeId=:storeId AND (startTime<=:endTime AND endTime>=:startTime)',[':id'=>$result['id'],':endTime'=>strtotime($result['endTime']),':startTime'=>strtotime($result['startTime']),':storeId'=>$storeId,':uniacid'=>$this->wqData['uniacid']])->one(); if($info){ return $this->result(2,'同一时间段只能创建一个活动!'); } $data['changeAt']=time(); $re = Yii::$app->db->createCommand()->update('{{%ybwm_roll_bag}}', $data, 'id=:id', ['id' =>$result['id']])->execute(); }else{ $info=(new \yii\db\Query()) ->from('{{%ybwm_roll_bag}}') ->where('uniacid=:uniacid AND deleteAt=0 AND storeId=:storeId AND (startTime<=:endTime AND endTime>=:startTime)',[':endTime'=>strtotime($result['endTime']),':startTime'=>strtotime($result['startTime']),':storeId'=>$storeId,':uniacid'=>$this->wqData['uniacid']])->one(); if($info){ return $this->result(2,'同一时间段只能创建一个活动!'); } $data['uniacid']=$this->wqData['uniacid']; $data['createdAt']=time(); try{ $re = Yii::$app->db->createCommand()->insert('{{%ybwm_roll_bag}}', $data)->execute(); }catch (\Exception $e){ print_R($e);die; } } if($re){ return $this->result(1,'成功'); }else{ return $this->result(2,'网络异常,请稍后再试'); } } //修改券包活动 public function actionModifyRollBag(){ $post=axios_request(); if($post['type']==1){ //显示隐藏 $data['display']=$post['display']; } if($post['type']==2){ //删除 $data['deleteAt']=time(); } $data['changeAt']=time(); $res = Yii::$app->db->createCommand()->update('{{%ybwm_roll_bag}}', $data, 'id=:id', ['id' =>$post['id']])->execute(); if($res){ return $this->result(1,'成功'); }else{ return $this->result(2,'网络异常,请稍后再试'); } } }