Răsfoiți Sursa

门店转移

linwu 2 ani în urmă
părinte
comite
1a2c8fe84b

+ 210 - 176
app/worker/controller/Agent.php

@@ -1,206 +1,240 @@
 <?php
+
 namespace app\worker\controller;
 
 use app\worker\BaseController;
-use app\common\model\Worker as WorkerModel;
 use app\common\model\Agent as AgentModel;
 use app\common\model\Broker as BrokerModel;
+use app\common\model\ComjobsReport as ComjobsReportModel;
 use app\common\model\User as UserModel;
 
 use app\common\validate\Agent as AgentValidate;
 use think\exception\ValidateException;
 
-use think\facade\Session;
 use think\facade\Db;
 use think\facade\Request;
 
 class Agent extends BaseController
 {
-	
-	public function agentList()
-	{
-		return view('agent/agentlist');
-	}
-	
-	public function agentForm()
-	{
-		$workerid = $this->access_worker['id'];
-		$id = input('id/d, 0');
-		$agent = AgentModel::where('workerid','=',$workerid)->findOrEmpty($id);
-		return view('agent/agentform',[
-			'agent'		=> $agent,
-			'worker'	=> $this->access_worker
-		]);
-	}
-	
-	public function editAgent()
-	{
-		$workerid = $this->access_worker['id'];
-		$id = input('id/d');
-		$vdata = array(
-			'id'			=> $id,
-			'loginname'		=> input('loginname/s', ""),
-			'idnumber'		=> input('idnumber/s', "")
-		);
-		try {
-			validate(AgentValidate::class)->check($vdata);
-		} catch (ValidateException $e) {
-			exit(json_encode(array(
-				'code' 	=> 1,
-				'msg'	=> $e->getError()
-			)));
-		}
-		$muser = UserModel::where(['mobile'=>input('musermobile/s', '')])->findOrEmpty();
-		if ($muser->isEmpty()){
-			exit(json_encode(array(
-				'code' 	=> 1,
-				'msg'	=> "关联的用户不存在。"
-			)));
-		}
-		$data = [
-			'userid'		=> $muser->id,
-			'workerid'		=> $workerid,
-			'loginname'  	=> input('loginname/s', ""),
-			'idnumber'  	=> input('idnumber/s', ""),
-			'title'			=> input('title/s', ""),
-			'tilpic'		=> input('tilpic/s', ""),
-			'picall'		=> input('picall/a', array()),
-			'realname'  	=> input('realname/s', ""),
-			'mobile'    	=> input('mobile/s', ""),
-			'telephone'		=> input('telephone/s', ""),
-			'latitude'		=> input('latitude/f', 0.00),
-			'longitude'		=> input('longitude/f', 0.00),
-			'province'		=> input('province/s', ""),
-			'city'			=> input('city/s', ""),
-			'district'		=> input('district/s', ""),
-			'address'		=> input('address/s', ""),
-			'details'		=> input('details/s', ""),
-			'priority'		=> input('priority/d', 0),
-			'remark'		=> input('remark/s', ""),
-			'status'		=> input('status/d', 0)
-		];
-		$password = input('password/s', "");
-		if (empty($id)){
-			$data['password'] = empty($password) ? md5("123456789") : md5($password);
-			$data['createtime'] = time();
-			$agent = AgentModel::create($data);
-		}else{
-			if (!empty($password)){
-				$data['password'] = md5($password);
-			}
-			$agent = AgentModel::find($id);
-			$agent->save($data);
-		}
-		BrokerModel::update([
-			'workerid' => $workerid
-		],['agentid'=>$agent->id]);
-		exit(json_encode(array(
-			'code' 	=> 0
-		)));
-	}
-
-	public function agent_join()
+
+    public function agentList()
     {
-        if(Request::isAjax()){
-            $data['realname'] = trim(input('post.realname/s'));
-            $data['mobile'] = trim(input('post.mobile/s'));
-            $data['address'] = trim(input('post.province/s')).trim(input('post.city/s')).trim(input('post.district/s')).trim(input('post.address/s'));
-            $data['idcard'] = trim(input('post.idcard/s'));
-            $data['recommender'] = trim(input('post.recommender/s'));
+        return view('agent/agentlist');
+    }
+
+    public function agentForm()
+    {
+        $workerid = $this->access_worker['id'];
+        $id       = input('id/d, 0');
+        $agent    = AgentModel::where('workerid', '=', $workerid)->findOrEmpty($id);
+        return view('agent/agentform', [
+            'agent'  => $agent,
+            'worker' => $this->access_worker,
+        ]);
+    }
+
+    public function editAgent()
+    {
+        $workerid = $this->access_worker['id'];
+        $id       = input('id/d');
+        $vdata    = [
+            'id'        => $id,
+            'loginname' => input('loginname/s', ""),
+            'idnumber'  => input('idnumber/s', ""),
+        ];
+        try {
+            validate(AgentValidate::class)->check($vdata);
+        } catch (ValidateException $e) {
+            exit(json_encode([
+                'code' => 1,
+                'msg'  => $e->getError(),
+            ]));
+        }
+        $muser = UserModel::where(['mobile' => input('musermobile/s', '')])->findOrEmpty();
+        if ($muser->isEmpty()) {
+            exit(json_encode([
+                'code' => 1,
+                'msg'  => "关联的用户不存在。",
+            ]));
+        }
+        $data     = [
+            'userid'    => $muser->id,
+            'workerid'  => $workerid,
+            'loginname' => input('loginname/s', ""),
+            'idnumber'  => input('idnumber/s', ""),
+            'title'     => input('title/s', ""),
+            'tilpic'    => input('tilpic/s', ""),
+            'picall'    => input('picall/a', []),
+            'realname'  => input('realname/s', ""),
+            'mobile'    => input('mobile/s', ""),
+            'telephone' => input('telephone/s', ""),
+            'latitude'  => input('latitude/f', 0.00),
+            'longitude' => input('longitude/f', 0.00),
+            'province'  => input('province/s', ""),
+            'city'      => input('city/s', ""),
+            'district'  => input('district/s', ""),
+            'address'   => input('address/s', ""),
+            'details'   => input('details/s', ""),
+            'priority'  => input('priority/d', 0),
+            'remark'    => input('remark/s', ""),
+            'status'    => input('status/d', 0),
+        ];
+        $password = input('password/s', "");
+        if (empty($id)) {
+            $data['password']   = empty($password) ? md5("123456789") : md5($password);
             $data['createtime'] = time();
-            $data['status'] = (int)1;
+            $agent              = AgentModel::create($data);
+        } else {
+            if (!empty($password)) {
+                $data['password'] = md5($password);
+            }
+            $agent = AgentModel::find($id);
+            $agent->save($data);
+        }
+        BrokerModel::update([
+            'workerid' => $workerid,
+        ], ['agentid' => $agent->id]);
+        exit(json_encode([
+            'code' => 0,
+        ]));
+    }
+
+    public function agent_join()
+    {
+        if (Request::isAjax()) {
+            $data['realname']    = trim(input('post.realname/s'));
+            $data['mobile']      = trim(input('post.mobile/s'));
+            $data['address']     = trim(input('post.province/s')) . trim(input('post.city/s')) . trim(input('post.district/s')) . trim(input('post.address/s'));
+            $data['idcard']      = trim(input('post.idcard/s'));
+            $data['recommender'] = trim(input('post.recommender/s'));
+            $data['createtime']  = time();
+            $data['status']      = (int)1;
 
             $res = Db::name('agent_form')->insert($data);
 
-            if($res){
+            if ($res) {
                 $rtn['code'] = 0;
-                $rtn['msg'] = '您的申请已提交,请静心等待';
-            }else{
+                $rtn['msg']  = '您的申请已提交,请静心等待';
+            } else {
                 $rtn['code'] = 1;
-                $rtn['msg'] = '对不起,您的申请失败,请重新申请';
+                $rtn['msg']  = '对不起,您的申请失败,请重新申请';
             }
-            return  $rtn;
-        }else{
+            return $rtn;
+        } else {
             return view('agent/agent_join');
         }
 
     }
-	
-	public function fieldAgent()
-	{
-		$workerid = $this->access_worker['id'];
-		$id = input('id/d',0); 
-		$agent = AgentModel::where('workerid','=',$workerid)->findOrEmpty($id);
-		if ($agent->isEmpty()){
-			exit(json_encode(array(
-				'code' 	=> 1,
-				'msg'	=> "信息不存在"
-			)));
-		}else{
-			$agent->save([
-				input('field/s')  => input('value')
-			]);
-		}
-		exit(json_encode(array(
-			'code' 	=> 0
-		)));
-	}
-	
-	public function delAgent()
-	{
-		$workerid = $this->access_worker['id'];
-		$password = input('password');
-		if ( $this->access_worker['password'] !== md5($password) ){
-			exit(json_encode(array(
-				'code' 	=> 1,
-				'msg'	=> "操作密码验证失败"
-			)));
-		}
-		$idarr = input('idarr/a');
-		$agent = AgentModel::where('workerid','=',$workerid)->whereIn('id',$idarr)->select();
-		$result = $agent->delete();
-		if ($result){
-			exit(json_encode(array(
-				'code' 	=> 0,
-				'msg'	=> ""
-			)));
-		}
-		exit(json_encode(array(
-			'code' 	=> 1,
-			'msg'	=> "删除失败,请稍后重试"
-		)));
-	}
-	
-	public function listAgent()
-	{
-		$workerid = $this->access_worker['id'];
-		$limit = input('limit');
-		$page = input('page');
-		$map = array();
-		$map[] = ['workerid', '=', $workerid];
-		$keywords = input('keywords/s');
-		if (!empty($keywords)){
-			$map[] =['idnumber', 'like', '%'.$keywords.'%'];
-		}
-		$status = input('status/d');
-		if (!empty($status)){
-			$map[] = ['status', '=', $status];
-		}
-		$list = AgentModel::with(['muser'])->where($map)->order(['priority'=>'DESC','id'=>'DESC'])->limit($limit)->page($page)->append(['status_text'])->select();
-		$count = AgentModel::where($map)->count();
-		if ($count==0){
-			exit(json_encode(array(
-				'code' 	=> 1,
-				'msg'	=> "未查询到数据"
-			)));
-		}
-		exit(json_encode(array(
-			'code' 	=> 0,
-			'msg'	=> "",
-			'count' => $count,
-			'data'  => $list
-		)));
-	}
-	
 
+    public function fieldAgent()
+    {
+        $workerid = $this->access_worker['id'];
+        $id       = input('id/d', 0);
+        $agent    = AgentModel::where('workerid', '=', $workerid)->findOrEmpty($id);
+        if ($agent->isEmpty()) {
+            exit(json_encode([
+                'code' => 1,
+                'msg'  => "信息不存在",
+            ]));
+        } else {
+            $agent->save([
+                input('field/s') => input('value'),
+            ]);
+        }
+        exit(json_encode([
+            'code' => 0,
+        ]));
+    }
+
+    public function delAgent()
+    {
+        $workerid   = $this->access_worker['id'];
+        $idarr      = input('idarr/a');
+        $broker_ids = BrokerModel::whereIn('agentid', $idarr)->column('id');
+        if (!empty($broker_ids)) {
+            BrokerModel::destroy($broker_ids,true);
+            UserModel::where('brokerid', 'in', $broker_ids)->update(['brokerid' => 0]);
+        }
+        AgentModel::destroy(function($query)use($workerid,$idarr){
+            $query->where('workerid', '=', $workerid)->whereIn('id', $idarr);
+        },true);
+        exit(json_encode([
+            'code' => 0,
+            'msg'  => "",
+        ]));
+    }
+
+    public function listAgent()
+    {
+        $workerid = $this->access_worker['id'];
+        $limit    = input('limit');
+        $page     = input('page');
+        $map      = [];
+        $map[]    = ['workerid', '=', $workerid];
+        $keywords = input('keywords/s');
+        if (!empty($keywords)) {
+            $map[] = ['idnumber', 'like', '%' . $keywords . '%'];
+        }
+        $status = input('status/d');
+        if (!empty($status)) {
+            $map[] = ['status', '=', $status];
+        }
+        $list  = AgentModel::with(['muser'])->where($map)->order(['priority' => 'DESC', 'id' => 'DESC'])->limit($limit)->page($page)->append(['status_text'])->select();
+        $count = AgentModel::where($map)->count();
+        if ($count == 0) {
+            exit(json_encode([
+                'code' => 1,
+                'msg'  => "未查询到数据",
+            ]));
+        }
+        exit(json_encode([
+            'code'  => 0,
+            'msg'   => "",
+            'count' => $count,
+            'data'  => $list,
+        ]));
+    }
+
+    public function transferfrom()
+    {
+        $agent_id   = input('agent_id/d, 0');
+        $agent_list = AgentModel::where('status', 1)->where('id', '<>', $agent_id)->select();
+        return view('agent/transferform', [
+            'origin_agent_id' => $agent_id,
+            'agent_list'      => $agent_list,
+        ]);
+    }
+
+    public function edittransfer()
+    {
+        $origin_agent_id = input('origin_agent_id/d, 0');
+        $agent_id        = input('agent_id/d, 0');
+        if (empty($origin_agent_id) || empty($agent_id)) {
+            exit(json_encode([
+                'code' => 1,
+                'msg'  => "参数错误",
+            ]));
+        }
+        if ($origin_agent_id == $agent_id) {
+            exit(json_encode([
+                'code' => 1,
+                'msg'  => "不可以转移给自己",
+            ]));
+        }
+
+        $origin_agent = AgentModel::where('id', $origin_agent_id)->find();
+        $agent        = AgentModel::where('id', $agent_id)->find();
+        if (empty($origin_agent) || empty($agent)) {
+            exit(json_encode([
+                'code' => 1,
+                'msg'  => "参数错误",
+            ]));
+        }
+
+        BrokerModel::where('agentid', $origin_agent_id)->update(['agent_id' => $agent_id, 'workerid' => $agent['workerid']]);
+        ComjobsReportModel::where('agentid', $origin_agent_id)->update(['agent_id' => $agent_id, 'workerid' => $agent['workerid']]);
+        exit(json_encode([
+            'code' => 0,
+        ]));
+    }
 }

+ 25 - 22
app/worker/view/agent/agentlist.html

@@ -38,9 +38,10 @@
 				{{#  } }}
 			</script>
 			<script type="text/html" id="setTpl">
+				<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="transfer"><i class="layui-icon layui-icon-spread-left"></i>下线转移</a>
 				<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
-						<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
-					</script>
+				<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
+			</script>
 		</div>
 	</div>
 </div>
@@ -77,7 +78,7 @@
 					{ field: 'address', width: 200, title: '详细地址', hide: 'true', edit: 'text' },
 					{ field: 'createtime', width: 170, title: '创建时间', sort: true },
 					{ field: 'status_text', title: '状态', minWidth: 80, align: 'center' },
-					{ title: '操作', width: 150, align: 'center', fixed: 'right', toolbar: '#setTpl' }
+					{ title: '操作', width: 250, align: 'center', fixed: 'right', toolbar: '#setTpl' }
 				]
 			],
 			page: true,
@@ -125,7 +126,7 @@
 					title: '敏感操作,请验证密码'
 				}, function(value, index) {
 					layer.close(index);
-					layer.confirm('确定删除此管理员吗?', function(index) {
+					layer.confirm('确定删除此门店吗?删除后门店下的经纪人都将变为无主', function(index) {
 						admin.req({
 							url: setter.baseWorkerUrl + 'agent/delagent',
 							data: {
@@ -155,25 +156,18 @@
 		table.on('tool(LAY-agent-agentlist-table)', function(obj) {
 			var data = obj.data;
 			if (obj.event === 'del') {
-				layer.prompt({
-					formType: 1,
-					title: '敏感操作,请验证密码'
-				}, function(value, index) {
-					layer.close(index);
-					layer.confirm('确定删除此管理员吗?', function(index) {
-						admin.req({
-							url: setter.baseWorkerUrl + 'agent/delagent',
-							data: {
-								password: value,
-								idarr: [data.id]
-							},
-							done: function(res) {
-								obj.del();
-								layer.msg('已删除');
-							}
-						});
-						layer.close(index);
+				layer.confirm('确定删除此门店吗?删除后门店下的经纪人都将变为无主', function(index) {
+					admin.req({
+						url: setter.baseWorkerUrl + 'agent/delagent',
+						data: {
+							idarr: [data.id]
+						},
+						done: function(res) {
+							obj.del();
+							layer.msg('已删除');
+						}
 					});
+					layer.close(index);
 				});
 			} else if (obj.event === 'edit') {
 				var index = layer.open({
@@ -184,6 +178,15 @@
 					area: ['550px', '550px']
 				});
 				layer.full(index);
+			} else if (obj.event === 'transfer') {
+				var index = layer.open({
+					type: 2,
+					title: '转移下线',
+					content: 'transferfrom.html?agent_id=' + data.id,
+					maxmin: true,
+					area: ['750px', '480px']
+				});
+				layer.full(index);
 			}
 		});
 

+ 59 - 0
app/worker/view/agent/transferform.html

@@ -0,0 +1,59 @@
+<div class="layui-fluid">
+    <div class="layui-row layui-col-space15">
+        <div class="layui-col-md12">
+            <div class="layui-card">
+                <div class="layui-card-header">下线转移</div>
+                <div class="layui-card-body" pad15>
+                    <div class="layui-form layui-form-pane" lay-filter="LAY-broker-transferform-edit">
+                        <input type="hidden" name="origin_agent_id" value="{$origin_agent_id}">
+                        <div class="layui-form-item">
+                            <label class="layui-form-label">对方店名</label>
+                            <div class="layui-input-block" id="agent_id">
+                            </div>
+                        </div>
+                        <div class="layui-form-item">
+                            <div class="layui-input-block">
+                                <input type="button" lay-submit lay-filter="LAY-broker-transferform-edit-submit"
+                                       value="确认提交" class="layui-btn">
+                            </div>
+                        </div>
+                    </div>
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
+
+<script>
+    layui.config({
+        base: '/static/echoui/' //静态资源所在路径
+    }).extend({
+        index: 'lib/index' //主入口模块
+    }).use(['index', 'form', 'set', 'upload','selectN', 'layarea'], function () {
+        var $ = layui.$, setter = layui.setter, admin = layui.admin, selectN = layui.selectN,form = layui.form;
+        form.render();
+
+        var workeragent = selectN({
+            elem: '#agent_id',
+            search: [true],
+            tips: ["请选择对方店名"],
+            data: {$agent_list|raw},
+            field: { idName: 'id', titleName: 'title'}
+        });
+
+        form.on('submit(LAY-broker-transferform-edit-submit)', function (obj) {
+            var index = parent.layer.getFrameIndex(window.name);
+            admin.req({
+                url: setter.baseAgentUrl + 'agent/edittransfer',
+                data: obj.field,
+                done: function (res) {
+                    layer.msg("提交成功", {
+                        icon: 1
+                    });
+                    parent.layui.table.reload('LAY-broker-brokerlist-table'); //重载表格
+                    parent.layer.close(index);
+                }
+            });
+        });
+    });
+</script>

+ 3 - 3
app/worker/view/index.html

@@ -168,9 +168,9 @@
 							<dd data-name="agentlist">
 								<a lay-href="{:url('/agent/agent_join')}" lay-text="申请加盟">申请加盟</a>
 							</dd>
-							<!--<dd data-name="agentlist">-->
-							<!--	<a lay-href="{:url('/agent/agentlist')}" lay-text="代理门店">代理门店</a>-->
-							<!--</dd>-->
+							<dd data-name="agentlist">
+								<a lay-href="{:url('/agent/agentlist')}" lay-text="代理门店">代理门店</a>
+							</dd>
 
 							<!--<dd data-name="brokerlist">-->
 							<!--	<a lay-href="{:url('/broker/brokerlist')}" lay-text="职业顾问">职业顾问</a>-->