108 lines
4.0 KiB
PHP
108 lines
4.0 KiB
PHP
<?php
|
|
namespace app\controllers\channel;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Yii;
|
|
use yii\web\Controller;
|
|
use app\models\common\Store;
|
|
//商品加料
|
|
class MaterialController extends CommonController{
|
|
public $enableCsrfValidation = false;
|
|
private $shop_id;
|
|
public function init(){
|
|
parent::init();
|
|
$this->shop_id=$this->storeId?:Store::getMainStore($this->wqData['uniacid'])['id'];
|
|
$this->shop_id=$this->shop_id?:0;
|
|
$request = Yii::$app->request;
|
|
if($request->isPost){
|
|
if(!$this->shop_id){
|
|
return $this->result(3,'无效的门店,请先添加商店');die;
|
|
}
|
|
}
|
|
|
|
}
|
|
public function actionMeteriaSave(){
|
|
$request = Yii::$app->request;
|
|
if ($request->isPost){
|
|
$result=axios_request();
|
|
$storeId=$result['storeId']?:$this->shop_id;
|
|
$data=array(
|
|
'sort'=>$result['sort'],
|
|
'name'=>$result['name'],
|
|
'uniacid'=>$this->wqData['uniacid'],
|
|
'storeId'=>$storeId,
|
|
'price'=>$result['price'],
|
|
'stock'=>$result['stock'],
|
|
);
|
|
if($result['id']){
|
|
$data['changeAt']=time();
|
|
$res=YII::$app->db->createCommand()->update('{{%ybwm_material}}',$data, 'id=:id', ['id' =>$result['id']])->execute();
|
|
}else{
|
|
$data['createdAt']=time();
|
|
$row= (new \yii\db\Query())
|
|
->from('{{%ybwm_material}}')
|
|
->where(['uniacid'=>$this->wqData['uniacid'],'deleteAt'=>0,'storeId'=>$storeId,'name'=>trim($result['name'])])
|
|
->one();
|
|
if($row){
|
|
return $this->result(2,'加料名已存在');
|
|
}
|
|
$res=Yii::$app->db->createCommand()->insert('{{%ybwm_material}}', $data)->execute();
|
|
}
|
|
if($res){
|
|
return $this->result(1,'成功');
|
|
}else{
|
|
return $this->result(2,'网络异常,请稍后再试');
|
|
}
|
|
}
|
|
}
|
|
|
|
public function actionGetMateriaList(){
|
|
$request = Yii::$app->request;
|
|
if($request->isGet){
|
|
$page=Yii::$app->request->get('page')?Yii::$app->request->get('page'):1;
|
|
$result=axios_request();
|
|
$storeId=$result['storeId']?:$this->shop_id;
|
|
$num = ($page - 1) * 10;
|
|
$limit = 10;
|
|
$table= (new \yii\db\Query())
|
|
->select('*')
|
|
->from('{{%ybwm_material}}')
|
|
->where(['deleteAt'=>0,'uniacid'=>$this->wqData['uniacid'],'storeId'=>$storeId]);
|
|
$count=$table->count();
|
|
$data=$table->orderBy('sort asc,id asc')->offset($num)
|
|
->limit($limit)
|
|
->all();
|
|
|
|
|
|
return $this->result(1,'成功',$data,$count);
|
|
}
|
|
}
|
|
public function actionChangeMateria(){
|
|
$request = Yii::$app->request;
|
|
if ($request->isPost){
|
|
$result=axios_request();
|
|
$re = YII::$app->db->createCommand()->update('{{%ybwm_material}}', ['display'=>$result['display']],'id=:id', ['id' =>$result['id']])->execute();
|
|
if($re){
|
|
return $this->result(1,'成功');
|
|
}else{
|
|
return $this->result(2,'网络异常,请稍后再试');
|
|
}
|
|
}
|
|
}
|
|
public function actionMateriaDel(){
|
|
$request = Yii::$app->request;
|
|
if ($request->isPost){
|
|
$result=axios_request();
|
|
if(is_array($result['id'])){
|
|
$res=YII::$app->db->createCommand()->update('{{%ybwm_material}}',['deleteAt'=>time()], ['in','id',$result['id']])->execute();
|
|
}else {
|
|
$res = YII::$app->db->createCommand()->update('{{%ybwm_material}}', ['deleteAt'=>time()], 'id=:id', ['id' => $result['id']])->execute();
|
|
}
|
|
if($res!==false){
|
|
return $this->result(1,'成功');
|
|
}else{
|
|
return $this->result(2,'网络异常,请稍后再试');
|
|
}
|
|
}
|
|
}
|
|
}
|