123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- <?php
- namespace app\worker\controller;
- use app\worker\BaseController;
- use app\common\model\Agent as AgentModel;
- use app\common\model\Broker as BrokerModel;
- use app\common\model\User as UserModel;
- use app\common\validate\Broker as BrokerValidate;
- use think\exception\ValidateException;
- class Broker extends BaseController
- {
-
- public function brokerList()
- {
- $workerid = $this->access_worker['id'];
- $agentlist = AgentModel::where('workerid','=',$workerid)->order(['id'=>'desc'])->select();
- return view('broker/brokerlist',[
- 'agentlist' => $agentlist
- ]);
- }
-
- public function brokerForm()
- {
- $workerid = $this->access_worker['id'];
- $id = input('id/d', 0);
- $broker = BrokerModel::where('workerid','=',$workerid)->findOrEmpty($id);
- $agentlist = AgentModel::where('workerid','=',$workerid)->order(['id'=>'desc'])->select();
- return view('broker/brokerform',[
- 'agentlist' => $agentlist,
- 'broker' => $broker,
- 'worker' => $this->access_worker
- ]);
- }
-
- public function editBroker()
- {
- $workerid = $this->access_worker['id'];
- $data = [
- 'agentid' => input('agentid/d', 0),
- 'title' => input('title/s', ""),
- 'mobile' => input('mobile/s', ""),
- 'weixin' => input('weixin/s', ""),
- 'qq' => input('qq/s', ""),
- 'province' => input('province/s', ""),
- 'city' => input('city/s', ""),
- 'district' => input('district/s', ""),
- 'details' => input('details/s', ""),
- 'powerreport' => input('powerreport/d', 0)==1 ? 1 : 2,
- 'status' => input('status/d', 0)==1 ? 1 : 2
- ];
- if (empty($id)){
- $id = input('id/d', 0);
- $vdata = array(
- 'id' => $id,
- 'mobile' => input('mobile/s')
- );
- try {
- validate(BrokerValidate::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' => "关联的用户不存在。"
- )));
- }
- $broker_user = BrokerModel::where('userid',$muser->id)->find();
- if (!empty($broker_user)) {
- exit(json_encode(array(
- 'code' => 1,
- 'msg' => "该用户已是经纪人。"
- )));
- }
- $data['userid'] = $muser->id;
- $data['workerid'] = $workerid;
- $data['createtime'] = time();
- $broker = BrokerModel::create($data);
- event('brokerAdd',$broker);
- }else{
- $broker = BrokerModel::find($id);
- $broker->save($data);
- }
- $muser->save([
- 'brokerid' => $broker->id
- ]);
- exit(json_encode(array(
- 'code' => 0
- )));
- }
-
- public function fieldBroker()
- {
- $workerid = $this->access_worker['id'];
- $id = input('id/d',0);
- $broker = BrokerModel::where('workerid','=',$workerid)->findOrEmpty($id);
- if ($broker->isEmpty()){
- exit(json_encode(array(
- 'code' => 1,
- 'msg' => "信息不存在"
- )));
- }else{
- $broker->save([
- input('field/s') => input('value/s', "")
- ]);
- }
- exit(json_encode(array(
- 'code' => 0
- )));
- }
-
- public function delBroker()
- {
- $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');
- $user_check = UserModel::whereIn('brokerid',$idarr)->find();
- if (!empty($user_check)) {
- exit(json_encode(array(
- 'code' => 1,
- 'msg' => "该经纪人还有下线,请先转移再删除"
- )));
- }
- $broker = BrokerModel::where('workerid','=',$workerid)->whereIn('id',$idarr)->select();
- $result = $broker->delete();
- if ($result){
- exit(json_encode(array(
- 'code' => 0,
- 'msg' => ""
- )));
- }
- exit(json_encode(array(
- 'code' => 1,
- 'msg' => "删除失败,请稍后重试"
- )));
- }
-
- public function listBroker()
- {
- $workerid = $this->access_worker['id'];
- $limit = input('limit/d',20);
- $page = input('page/d',1);
- $map = array();
- $map[] = ['workerid', '=', $workerid];
- $keywords = input('keywords/s');
- if (!empty($keywords)){
- $map[] =['title', 'like', '%'.$keywords.'%'];
- }
- $status = input('status/d');
- if (!empty($status)){
- $map[] = ['status', '=', $status];
- }
- $agentid = input('agentid/d');
- if (!empty($agentid)){
- $map[] = ['agentid', '=', $agentid];
- }
- $list = BrokerModel::with(['muser','worker','agent'])->withCount(['user'])->where($map)->order('id','DESC')->limit($limit)->page($page)->append(['status_text','powerreport_text'])->select();
- $count = BrokerModel::where($map)->count();
- if ($count==0){
- exit(json_encode(array(
- 'code' => 1,
- 'msg' => "未查询到数据"
- )));
- }
- exit(json_encode(array(
- 'code' => 0,
- 'msg' => "",
- 'count' => $count,
- 'data' => $list
- )));
- }
-
- }
|