103 lines
3.7 KiB
PHP
103 lines
3.7 KiB
PHP
<?php
|
|
namespace app\controllers\merchant;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Yii;
|
|
use yii\web\Controller;
|
|
use app\models\common\Store;
|
|
//商品标签
|
|
class GoodLabelController extends CommonController{
|
|
public $enableCsrfValidation = false;
|
|
public function actionGetLabelList(){
|
|
$request = Yii::$app->request;
|
|
if ($request->isGet){
|
|
$result=axios_request();
|
|
if($result['id']){
|
|
$table= (new \yii\db\Query())
|
|
->select('id, sort,name,display,color')
|
|
->from('{{%ybwm_core_label}}')
|
|
->where(['id'=>$result['id']]);
|
|
$re=$table->one();
|
|
}else{
|
|
$table= (new \yii\db\Query())
|
|
->select('id, sort,name,display,color')
|
|
->from('{{%ybwm_core_label}}')
|
|
->where(['deleteAt'=>0,'uniacid'=>$this->wqData['uniacid'],'storeId'=>$this->wqData['storeId']]);
|
|
$re=$table->all();
|
|
|
|
}
|
|
return $this->result(1,'成功',$re);
|
|
|
|
}
|
|
}
|
|
public function actionLabelSave(){
|
|
$request = Yii::$app->request;
|
|
if ($request->isPost){
|
|
$result=axios_request();
|
|
$storeId=$result['storeId']?:$this->wqData['storeId'];
|
|
if(!$storeId){
|
|
return $this->result(3,'无效的门店,请先添加商店');die;
|
|
}
|
|
$data=array(
|
|
'sort'=>$result['sort'],
|
|
'color'=>$result['color'],
|
|
'name'=>$result['name'],
|
|
'uniacid'=>$this->wqData['uniacid'],
|
|
'storeId'=>$storeId,
|
|
);
|
|
if($result['id']){
|
|
$re=YII::$app->db->createCommand()->update('{{%ybwm_core_label}}',$data, 'id=:id', ['id' =>$result['id']])->execute();
|
|
}else{
|
|
$data['createdAt']=time();
|
|
$row= (new \yii\db\Query())
|
|
->from('{{%ybwm_core_label}}')
|
|
->where(['uniacid'=>$this->wqData['uniacid'],'storeId'=>$storeId,'name'=>trim($result['name'])])
|
|
->one();
|
|
if($row){
|
|
return $this->result(2,'该商品标签已存在');
|
|
}
|
|
$re=Yii::$app->db->createCommand()->insert('{{%ybwm_core_label}}', $data)->execute();
|
|
}
|
|
|
|
|
|
if($re){
|
|
return $this->result(1,'成功');
|
|
}else{
|
|
return $this->result(2,'网络异常,请稍后再试');
|
|
}
|
|
}
|
|
}
|
|
|
|
public function actionChangeLabel(){
|
|
$request = Yii::$app->request;
|
|
if ($request->isPost){
|
|
$result=axios_request();
|
|
$re = YII::$app->db->createCommand()->update('{{%ybwm_core_label}}', ['display'=>$result['display']],'id=:id', ['id' =>$result['id']])->execute();
|
|
//dd($re);die;
|
|
if($re!==false){
|
|
return $this->result(1,'成功');
|
|
}else{
|
|
return $this->result(2,'网络异常,请稍后再试');
|
|
}
|
|
}
|
|
}
|
|
|
|
public function actionLabelDel(){
|
|
$request = Yii::$app->request;
|
|
if ($request->isPost){
|
|
$result=axios_request();
|
|
if(is_array($result['id'])){
|
|
$re=YII::$app->db->createCommand()->update('{{%ybwm_core_label}}',['deleteAt'=>time()], ['in','id',$result['id']])->execute();
|
|
}else {
|
|
$re = YII::$app->db->createCommand()->update('{{%ybwm_core_label}}', ['deleteAt' => time()], 'id=:id', ['id' => $result['id']])->execute();
|
|
}
|
|
if($re!==false){
|
|
return $this->result(1,'成功');
|
|
}else{
|
|
return $this->result(2,'网络异常,请稍后再试');
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|