canyin-project/ybcy/controllers/channel/RegionController.php
2024-11-01 16:07:54 +08:00

96 lines
3.2 KiB
PHP

<?php
namespace app\controllers\channel;
use Illuminate\Support\Facades\DB;
use Yii;
use yii\db\Expression;
class RegionController extends CommonController{
public $enableCsrfValidation = false;
public function actionRegionList(){
$result=axios_request();
$page=$result['page']?:1;
$size=$result['size']?:10;
$query=(new \yii\db\Query())->from('{{%ybo2ov2_region}} a')
->select('sort,id,name,(select count(*) from ims_ybo2ov2_store b where a.id=b.regionId)count,data');
$count=(clone $query)->count();
if($page){
$data=(clone $query)->offset(($page - 1) * $size)->limit($size)->orderBy('sort asc,id desc')->all();
}else{
$data=(clone $query)->orderBy('sort asc,id desc')->all();
}
foreach ($data as &$value){
$value['data']=@json_decode($value['data'],true);
}
//$arr[0]=['id'=>0,'name'=>'无'];
//$data=array_values(array_merge($arr,$data));
return $this->result(1,'成功',$data,$count);
}
public function actionRegionSave(){
$result=axios_request();
$data=array(
'sort'=>$result['sort'],
'name'=>$result['name'],
'userName'=>$result['userName'],
'passWord'=>$result['passWord'],
'userTel'=>$result['userTel'],
'lat'=>$result['lat'],
'lng'=>$result['lng'],
);
if(!$data['name']){
return $this->result(2,'请填写区域名称');
}
if(!$data['userName']){
return $this->result(2,'请填写真实姓名');
}
if(!$data['passWord']){
return $this->result(2,'请填写登录密码');
}
if(!$data['userTel']){
return $this->result(2,'请填写手机号码');
}
if($result['id']){
$data['changeAt']=time();
Yii::$app->db->createCommand()->update('{{%ybo2ov2_region}}', $data, ['id'=>$result['id']])->execute();
}else{
$data['createAt']=time();
Yii::$app->db->createCommand()->insert('{{%ybo2ov2_region}}', $data)->execute();
}
return $this->result(1,'成功');
}
public function actionRegionService(){
$result=axios_request();
if(!$result['id']){
return $this->result(2,'参数有误');
}
$data=array(
'data'=>json_encode($result['data']),
);
if($result['id']){
$data['changeAt']=time();
Yii::$app->db->createCommand()->update('{{%ybo2ov2_region}}', $data, ['id'=>$result['id']])->execute();
}
return $this->result(1,'成功');
}
public function actionRegionDel(){
$result=axios_request();
if($result['id']){
Yii::$app->db->createCommand()->delete('{{%ybo2ov2_region}}', ['id'=>$result['id']])->execute();
}
return $this->result(1,'成功');
}
public function actionRegionDetail(){
$result=axios_request();
if($result['id']){
$data=(new \yii\db\Query())->from('{{%ybo2ov2_region}} a')
->where(['id'=>$result['id']])->one();
}
return $this->result(1,'成功',$data);
}
}