Broker.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. namespace app\agent\controller;
  3. use app\agent\BaseController;
  4. use app\common\model\Agent as AgentModel;
  5. use app\common\model\Broker as BrokerModel;
  6. use app\common\model\User as UserModel;
  7. use app\common\validate\Broker as BrokerValidate;
  8. use think\exception\ValidateException;
  9. class Broker extends BaseController
  10. {
  11. public function brokerList()
  12. {
  13. return view('broker/brokerlist');
  14. }
  15. public function brokerForm()
  16. {
  17. $id = input('id/d, 0');
  18. $broker = BrokerModel::findOrEmpty($id);
  19. $agent = $this->access_agent;
  20. return view('broker/brokerform',[
  21. 'agent' => $agent,
  22. 'broker' => $broker
  23. ]);
  24. }
  25. public function editBroker()
  26. {
  27. $agent = $this->access_agent;
  28. $id = input('id/d');
  29. $vdata = array(
  30. 'id' => $id,
  31. 'mobile' => input('mobile/s')
  32. );
  33. try {
  34. validate(BrokerValidate::class)->check($vdata);
  35. } catch (ValidateException $e) {
  36. exit(json_encode(array(
  37. 'code' => 1,
  38. 'msg' => $e->getError()
  39. )));
  40. }
  41. $musermap = array();
  42. $brokeridarr = BrokerModel::where('agentid','=',$agent['id'])->column('id');
  43. $musermap[] = ['brokerid', 'in', $brokeridarr];
  44. $musermap[] = ['brokerid', '<>', 0];
  45. $musermap[] = ['mobile', '=', input('musermobile/s', '')];
  46. $muser = UserModel::where($musermap)->findOrEmpty();
  47. if ($muser->isEmpty()){
  48. exit(json_encode(array(
  49. 'code' => 1,
  50. 'msg' => "关联的用户不存在。"
  51. )));
  52. }
  53. $data = [
  54. 'userid' => $muser->id,
  55. 'workerid' => $agent['workerid'],
  56. 'agentid' => $agent['id'],
  57. 'title' => input('title/s', ""),
  58. 'mobile' => input('mobile/s', ""),
  59. 'weixin' => input('weixin/s', ""),
  60. 'qq' => input('qq/s', ""),
  61. 'province' => input('province/s', ""),
  62. 'city' => input('city/s', ""),
  63. 'district' => input('district/s', ""),
  64. 'details' => input('details/s', ""),
  65. 'powerreport' => input('powerreport/d', 0)==1 ? 1 : 2,
  66. 'status' => input('status/d')==1 ? 1 : 2
  67. ];
  68. if (empty($id)){
  69. $data['createtime'] = time();
  70. $broker = BrokerModel::create($data);
  71. }else{
  72. $broker = BrokerModel::find($id);
  73. $broker->save($data);
  74. }
  75. exit(json_encode(array(
  76. 'code' => 0
  77. )));
  78. }
  79. public function fieldBroker()
  80. {
  81. $id = input('id/d',0);
  82. $broker = BrokerModel::findOrEmpty($id);
  83. if ($broker->isEmpty()){
  84. exit(json_encode(array(
  85. 'code' => 1,
  86. 'msg' => "信息不存在"
  87. )));
  88. }else{
  89. $broker->save([
  90. input('field/s') => input('value')
  91. ]);
  92. }
  93. exit(json_encode(array(
  94. 'code' => 0
  95. )));
  96. }
  97. public function delBroker()
  98. {
  99. $idarr = input('idarr/a');
  100. $broker = BrokerModel::where('role',2)->whereIn('id',$idarr)->select();
  101. $result = $broker->delete();
  102. if ($result){
  103. exit(json_encode(array(
  104. 'code' => 0,
  105. 'msg' => ""
  106. )));
  107. }
  108. exit(json_encode(array(
  109. 'code' => 1,
  110. 'msg' => "删除失败,请稍后重试"
  111. )));
  112. }
  113. public function listBroker()
  114. {
  115. $agentid = $this->access_agent['id'];
  116. $limit = input('limit/d',20);
  117. $page = input('page/d',1);
  118. $map = array();
  119. $map[] = ['agentid', '=', $agentid];
  120. $keywords = input('keywords/s');
  121. if (!empty($keywords)){
  122. $map[] =['title', 'like', '%'.$keywords.'%'];
  123. }
  124. $status = input('status/d');
  125. if (!empty($status)){
  126. $map[] = ['status', '=', $status];
  127. }
  128. $list = BrokerModel::with(['agent','muser'])->withCount(['user'])->where($map)->order('id','DESC')->limit($limit)->page($page)->append(['status_text','powerreport_text'])->select();
  129. $count = BrokerModel::where($map)->count();
  130. if ($count==0){
  131. exit(json_encode(array(
  132. 'code' => 1,
  133. 'msg' => "未查询到数据"
  134. )));
  135. }
  136. exit(json_encode(array(
  137. 'code' => 0,
  138. 'msg' => "",
  139. 'count' => $count,
  140. 'data' => $list
  141. )));
  142. }
  143. }