157 lines
6.1 KiB
PHP
157 lines
6.1 KiB
PHP
|
<?php
|
||
|
/**
|
||
|
* Created by PhpStorm.
|
||
|
* User: Administrator
|
||
|
* Date: 2021/6/7 0007
|
||
|
* Time: 14:15
|
||
|
*/
|
||
|
|
||
|
namespace app\controllers\channel;
|
||
|
use app\models\common\Store;
|
||
|
use Yii;
|
||
|
class WineStorageController extends CommonController{
|
||
|
public $enableCsrfValidation = false;
|
||
|
private $shop_id;
|
||
|
function init(){
|
||
|
parent::init();
|
||
|
$this->shop_id=$this->storeId?:Store::getMainStore($this->wqData['uniacid'])['id'];
|
||
|
$this->shop_id=$this->shop_id?:0;
|
||
|
}
|
||
|
//酒牌名称列表
|
||
|
public function actionBrandList(){
|
||
|
$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_storage_brand}}')
|
||
|
->select('id,name,body,from_unixtime(createdAt) createdAt,display,sort')
|
||
|
->where(['deleteAt'=>0,'uniacid'=>$this->wqData['uniacid'],'storeId'=>$storeId]);
|
||
|
$list=$table->offset($num)
|
||
|
->limit($limit)->orderBy('sort asc,id desc')->all();
|
||
|
$count=$table->count();
|
||
|
return $this->result(1, '成功',$list,$count);
|
||
|
}
|
||
|
//存/取列表
|
||
|
public function actionOrderList(){
|
||
|
$result=axios_request();
|
||
|
$keyword=$result['keyword'];
|
||
|
$timeType=$result['timeType']?:1;
|
||
|
$timeArr=$this->timeArr[$timeType];
|
||
|
$storeId=$result['storeId']?:$this->shop_id;
|
||
|
$page=$result['page'];
|
||
|
$type=$result['type']?:1;
|
||
|
$storageId=$result['storageId'];
|
||
|
$num=($page-1)*10;
|
||
|
$limit=10;
|
||
|
$table=(new \yii\db\Query())
|
||
|
->select('a.storageId,a.origin,b.userName as nickName,a.id,a.userId,a.outTradeNo,a.userName,a.userTel,a.name,
|
||
|
a.totalNum,a.takeNum,a.note,a.state,a.surplusNum,from_unixtime(a.createdAt) as createdAt,from_unixtime(a.endAt) as endAt')
|
||
|
->from('{{%ybwm_storage_order}} as a')
|
||
|
->join('LEFT JOIN', '{{%ybwm_member}} as b', 'b.id = a.userId')
|
||
|
->where(['a.type'=>$type,'a.deleteAt'=>0,'a.uniacid'=>$this->wqData['uniacid'],'a.storeId'=>$storeId]);
|
||
|
if($timeArr){
|
||
|
$table->andWhere('a.createdAt>=:startTime AND a.createdAt<=:endTime',[':startTime'=>$timeArr['startTime'],':endTime'=>$timeArr['endTime']]);
|
||
|
}
|
||
|
if($keyword){
|
||
|
$table->andWhere(['or',['like','a.userName',$keyword],['like','a.userTel',$keyword]]);
|
||
|
}
|
||
|
if($storageId){
|
||
|
$table->andWhere('a.storageId='.$storageId);
|
||
|
}
|
||
|
if(!$page){
|
||
|
$list=$table->orderBy('a.id desc')->all();
|
||
|
return $this->result(1, '成功',$list);
|
||
|
}
|
||
|
$list=$table->offset($num)
|
||
|
->limit($limit)->orderBy('a.id desc')->all();
|
||
|
$count=$table->count();
|
||
|
return $this->result(1, '成功',$list,$count);
|
||
|
}
|
||
|
//修改酒牌名称
|
||
|
public function actionSaveBrand() {
|
||
|
$result=axios_request();
|
||
|
$request = Yii::$app->request;
|
||
|
$storeId=$result['storeId']?:$this->shop_id;
|
||
|
if($request->isGet){
|
||
|
$info=(new \yii\db\Query())
|
||
|
->from('{{%ybwm_storage_brand}}')
|
||
|
->where('id=:id',[':id'=>$result['id']])->one();
|
||
|
return $this->result(1, '成功',$info);
|
||
|
}
|
||
|
if(!$result['name']){
|
||
|
return $this->result(2,'名称不能为空!');
|
||
|
}
|
||
|
$data['name'] = $result['name'];
|
||
|
$data['sort'] = $result['sort'];
|
||
|
$data['body'] = $result['body'];
|
||
|
$data['display'] = 1;
|
||
|
$data['storeId'] = $storeId;
|
||
|
if($result['id']){
|
||
|
$data['changeAt']=time();
|
||
|
$re = Yii::$app->db->createCommand()->update('{{%ybwm_storage_brand}}', $data, 'id=:id', ['id' =>$result['id']])->execute();
|
||
|
}else{
|
||
|
$data['uniacid']=$this->wqData['uniacid'];
|
||
|
$data['createdAt']=time();
|
||
|
$re = Yii::$app->db->createCommand()->insert('{{%ybwm_storage_brand}}', $data)->execute();
|
||
|
}
|
||
|
if($re){
|
||
|
return $this->result(1,'成功');
|
||
|
}else{
|
||
|
return $this->result(2,'网络异常,请稍后再试');
|
||
|
}
|
||
|
}
|
||
|
//修改酒牌名称状态
|
||
|
public function actionModifyBrand() {
|
||
|
$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_storage_brand}}', $data, 'id=:id', ['id' =>$post['id']])->execute();
|
||
|
if($res){
|
||
|
return $this->result(1,'成功');
|
||
|
}else{
|
||
|
return $this->result(2,'网络异常,请稍后再试');
|
||
|
}
|
||
|
}
|
||
|
//审核寄存信息
|
||
|
public function actionOperationStorage() {
|
||
|
$post=axios_request();
|
||
|
$order=(new \yii\db\Query())
|
||
|
->from('{{%ybwm_storage_order}}')
|
||
|
->where('id=:id',[':id'=>$post['id']])->one();
|
||
|
if(!$order){
|
||
|
return $this->result(2, '信息不存在!');
|
||
|
}
|
||
|
if ($post['type'] == 'adopt') {
|
||
|
$data['state']=2;
|
||
|
}
|
||
|
if ($post['type'] == 'reject') {
|
||
|
$data['state']=3;
|
||
|
}
|
||
|
$res=Yii::$app->db->createCommand()->update('{{%ybwm_storage_order}}', $data, 'id=:id', ['id' =>$post['id']])->execute();
|
||
|
if ($res) {
|
||
|
if ($post['type'] == 'reject') {
|
||
|
$storage=(new \yii\db\Query())
|
||
|
->from('{{%ybwm_storage_order}}')
|
||
|
->where('id=:id',[':id'=>$order['storageId']])->one();
|
||
|
$takeNum=$storage['takeNum']-$order['takeNum'];
|
||
|
$storageData['takeNum']=$takeNum;
|
||
|
if($storage['totalNum']!=$takeNum){
|
||
|
$storageData['state']=2;
|
||
|
}
|
||
|
Yii::$app->db->createCommand()->update('{{%ybwm_storage_order}}', $storageData, 'id=:id', [':id' =>$order['storageId']])->execute();
|
||
|
}
|
||
|
return $this->result(1, '操作成功!');
|
||
|
} else {
|
||
|
return $this->result(2, '操作失败!');
|
||
|
}
|
||
|
}
|
||
|
}
|