135 lines
5.1 KiB
PHP
Executable File
135 lines
5.1 KiB
PHP
Executable File
<?php
|
|
|
|
namespace app\admin\logic\director;
|
|
|
|
use app\common\basics\Logic;
|
|
use app\common\model\DevRegion;
|
|
use app\common\model\distribution\Distributioncity;
|
|
use app\common\model\user\User;
|
|
use app\common\server\UrlServer;
|
|
use think\facade\Db;
|
|
|
|
class DirectorLogic extends Logic
|
|
{
|
|
public static function lists($get)
|
|
{
|
|
$where[] = ['d_state','<>', '2'];
|
|
|
|
$director_count = Distributioncity::where($where)->count();
|
|
|
|
$director_list = Distributioncity::where($where)
|
|
->page($get['page'],$get['limit'])
|
|
->order('d_id desc')
|
|
->select()
|
|
->toArray();
|
|
foreach($director_list as $key=>$value){
|
|
$user_msg= User::where("id",$value['user_id'])->find();
|
|
$devRegion_city_msg= DevRegion::where("id",$value['city_id'])->find();
|
|
$devRegion_pro_msg= DevRegion::where("id",$value['province_id'])->find();
|
|
$devRegion_district_msg= DevRegion::where("id",$value['district_id'])->find();
|
|
$director_list[$key]['city_name'] = $devRegion_city_msg['name'];
|
|
$director_list[$key]['pro_name'] = $devRegion_pro_msg['name'];
|
|
$director_list[$key]['district_name'] = $devRegion_district_msg['name'];
|
|
$director_list[$key]['nickname'] = $user_msg['nickname'];
|
|
$director_list[$key]['avatar'] = UrlServer::getFileUrl($user_msg['avatar']);
|
|
}
|
|
return ['count'=>$director_count , 'lists'=>$director_list];
|
|
}
|
|
/**
|
|
* NOTE: 新增城市及省管理人
|
|
* @author: xc
|
|
* @param $post
|
|
* @return bool
|
|
*/
|
|
public static function add($post)
|
|
{
|
|
$user_msg = User::where("sn",$post['sn'])->find();
|
|
if($user_msg != null){
|
|
if($post['d_type'] == 3){
|
|
$distributiondistrict_msg = Distributioncity::where("district_id",$post['district_id'])->where("d_state",1)->where("d_type",3)->find();
|
|
if($distributiondistrict_msg!=null){
|
|
return 3;
|
|
}
|
|
}
|
|
if($post['d_type'] == 2){
|
|
$distributioncity_msg = Distributioncity::where("city_id",$post['city_id'])->where("d_state",1)->where("d_type",2)->find();
|
|
if($distributioncity_msg!=null){
|
|
return 2;
|
|
}
|
|
}
|
|
if($post['d_type'] == 1){
|
|
$distributionpro_msg = Distributioncity::where("province_id",$post['province_id'])->where("d_state",1)->where("d_type",1)->find();
|
|
if($distributionpro_msg!=null){
|
|
return 1;
|
|
}
|
|
}
|
|
$dcity = Distributioncity::create([
|
|
'user_id' => $user_msg['id'],
|
|
'sn' => $post['sn'],
|
|
'd_type' => $post['d_type'],
|
|
'city_id' => $post['city_id'],
|
|
'province_id' => $post['province_id'],
|
|
'district_id' => $post['district_id'],
|
|
'd_dtime' => date("Y-m-d H:i:s")
|
|
]);
|
|
if($dcity){
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
public static function edit($post)
|
|
{
|
|
try {
|
|
if($post['d_type'] == 3){
|
|
$distributiondistrict_msg = Distributioncity::where("district_id",$post['district_id'])->where("d_state",1)->where("d_type",3)->find();
|
|
if($distributiondistrict_msg!=null){
|
|
return 3;
|
|
}
|
|
}
|
|
if($post['d_type'] == 2){
|
|
$distributioncity_msg = Distributioncity::where("city_id",$post['city_id'])->where("d_state",1)->where("d_type",2)->find();
|
|
if($distributioncity_msg!=null){
|
|
return 2;
|
|
}
|
|
}
|
|
if($post['d_type'] == 1){
|
|
$distributionpro_msg = Distributioncity::where("province_id",$post['province_id'])->where("d_state",1)->where("d_type",1)->find();
|
|
if($distributionpro_msg!=null){
|
|
return 1;
|
|
}
|
|
}
|
|
Distributioncity::update([
|
|
'd_type' => $post['d_type'],
|
|
'city_id' => $post['city_id'],
|
|
'province_id' => $post['province_id'],
|
|
'district_id' => $post['district_id'],
|
|
'd_dtime' => date("Y-m-d H:i:s")
|
|
], ['d_id'=>$post['d_id']]);
|
|
|
|
return true;
|
|
} catch (Exception $e) {
|
|
static::$error = $e->getMessage();
|
|
return false;
|
|
}
|
|
}
|
|
public static function detail($id)
|
|
{
|
|
$detail = Distributioncity::where("d_id",$id)->find();
|
|
return $detail;
|
|
}
|
|
public static function delDirector($d_id)
|
|
{
|
|
$data = [
|
|
'd_state' => 2
|
|
];
|
|
return Db::name('distribution_city')->where('d_id',$d_id)->update($data);
|
|
}
|
|
public static function stateDirector($id,$state)
|
|
{
|
|
$data = [
|
|
'd_state' => $state
|
|
];
|
|
return Db::name('distribution_city')->where('d_id',$id)->update($data);
|
|
}
|
|
} |