Agents.php 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014
  1. <?php
  2. namespace app\sys\controller;
  3. use think\facade\View;
  4. use app\model\Customer;
  5. use app\model\Employee;
  6. use app\model\CreditsSetting;
  7. use think\facade\Request;
  8. use app\model\AgentUser;
  9. use app\model\AgentIntegralLog;
  10. use app\model\AgentCustomerLog;
  11. use app\model\AgentIntegral;
  12. use app\model\Setting;
  13. use app\model\AgentApplyIntegral;
  14. use app\model\AgentArticle;
  15. use app\model\User;
  16. use app\model\AgentType;
  17. use app\model\AgentPrize;
  18. use app\model\AgentShareContent;
  19. use xiaohongwu\Vr;
  20. use app\model\Article;
  21. use app\model\MaterialCase;
  22. use app\model\Video;
  23. use app\model\CompanyStrength;
  24. use app\model\MaterialEvidence;
  25. use app\model\Building;
  26. use app\model\VrGroup;
  27. class Agents
  28. {
  29. /**
  30. * 经济人列表
  31. */
  32. public function agent_list()
  33. {
  34. $param = Request::param();
  35. $request = request();
  36. if (!request()->isAjax()) {
  37. //查询是否有需要核销的积分
  38. $is_review = AgentApplyIntegral::where([['root_id', '=', $request->employee->root_id], ['status', '=', 2]])->count();
  39. View::assign('is_review', $is_review);
  40. View::assign('employee', $request->employee);
  41. return View::fetch();
  42. }
  43. $where = [['root_id', '=', $request->employee->root_id]];
  44. if (!empty($param['keyword'])) {
  45. $empid = Employee::where([['name', 'like', $param['keyword'] . '%'], ['root_id', '=', $request->employee->root_id]])->field('id,name')->column('id');
  46. $where[] = ['agent_employee_id', 'in', $empid];
  47. }
  48. $list = AgentUser::with(['employee', 'agenttype'])
  49. ->withCount('customer')
  50. ->where($where)->page($param['page'], $param['limit'])
  51. ->order(['addtime' => 'desc'])
  52. ->select()
  53. ->toArray();
  54. foreach ($list as $key => $val) {
  55. $list[$key]['daodiannum'] = AgentCustomerLog::where([['agent_id', '=', $val['id']], ['status', '=', 1], ['type', '=', 1]])->count();
  56. $list[$key]['jiaodingnum'] = AgentCustomerLog::where([['agent_id', '=', $val['id']], ['status', '=', 1], ['type', '=', 2]])->count();
  57. $list[$key]['qiandannum'] = AgentCustomerLog::where([['agent_id', '=', $val['id']], ['status', '=', 1], ['type', '=', 3]])->count();
  58. $list[$key]['now_integral'] = AgentIntegralLog::where('agt_id', $val['id'])->order('id desc')->value('now_integral');
  59. }
  60. $count = AgentUser::where($where)->count();
  61. return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']);
  62. }
  63. /**
  64. * 修改经纪人账号状态
  65. */
  66. public function up_agt_accnumb()
  67. {
  68. $request = request();
  69. $param = $request->param();
  70. $ms = Agentuser::where([['id', '=', $param['id']], ['root_id', '=', $request->employee->root_id]])->find();
  71. $ms->status = $ms->status == 1 ? 2 : 1;
  72. $ms->save();
  73. if (!$ms) return json(['code' => 0, 'msg' => '修改失败']);
  74. return json(['code' => 0, 'msg' => '修改成功']);
  75. }
  76. /**
  77. * 经济人客户列表明细
  78. */
  79. public function agent_customer_list()
  80. {
  81. $request = request();
  82. // 页面展示
  83. if (!request()->isAjax()) {
  84. $param = Request::param();
  85. $agentid = $param['agentid'];
  86. View::assign('employee', $request->employee);
  87. View::assign('agentid', $agentid);
  88. return View::fetch();
  89. }
  90. // 数据请求
  91. $param = $request->param();
  92. // 检测经纪人是否存在
  93. $agent = AgentUser::where(['id' => $param['agentid'], 'root_id' => $request->employee->root_id])->find();
  94. if (empty($agent)) return json(['code' => 0, 'data' => [], 'count' => 0, 'msg' => '获取成功']);
  95. $where = [['agents_id', '=', $param['agentid']]];
  96. $list = Customer::with(['agentLog'])->where($where)->field('id,name,addtime')->page($param['page'], $param['limit'])->order(['addtime' => 'desc'])->select()->toArray();
  97. foreach ($list as $key => $val) {
  98. $all_integral = AgentIntegral::where([['customer_id', '=', $val['id']], ['status', '<>', 3]])->sum('integral');
  99. $list[$key]['all_integral'] = $all_integral;
  100. $daodiantime = $jiaodingtime = $qiandantime = 0;
  101. foreach ($val['agentLog'] as $v) {
  102. if ($v['type'] == 1) {
  103. $daodiantime = date('Y-m-d', strtotime($v['addtime']));
  104. }
  105. if ($v['type'] == 2) {
  106. $jiaodingtime = date('Y-m-d', strtotime($v['addtime']));
  107. }
  108. if ($v['type'] == 3) {
  109. $qiandantime = date('Y-m-d', strtotime($v['addtime']));
  110. }
  111. }
  112. $list[$key]['daodiantime'] = $daodiantime ? $daodiantime : 0;
  113. $list[$key]['qiandantime'] = $qiandantime ? $qiandantime : 0;
  114. $list[$key]['jiaodingtime'] = $jiaodingtime ? $jiaodingtime : 0;
  115. $list[$key]['employee'] = $request->employee; //加入后台操作人员信息判断馨居尚
  116. }
  117. $count = Customer::where($where)->count();
  118. return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']);
  119. }
  120. /**
  121. * 到访明细
  122. */
  123. public function agent_kehu_list()
  124. {
  125. $request = request();
  126. $param = $request->param();
  127. if (!request()->isAjax()) {
  128. $type = $param['type'];
  129. $agentid = $param['agentid'];
  130. View::assign('agentid', $agentid);
  131. View::assign('employee', $request->employee);
  132. if ($type == 1) return View::fetch('visit_number');
  133. if ($type == 2) return View::fetch('deposit_people');
  134. if ($type == 3) return View::fetch('sign_people');
  135. }
  136. $agent = AgentUser::where(['id' => $param['agentid'], 'root_id' => $request->employee->root_id])->find();
  137. if (!$agent) return json(['code' => 0, 'data' => [], 'count' => 0, 'msg' => '获取成功']);
  138. $where = [
  139. ['status', '=', 1],
  140. ['type', '=', $param['type']],
  141. ['agent_id', '=', $param['agentid']]
  142. ];
  143. $list = AgentCustomerLog::with(['customer'])->where($where)->page($param['page'], $param['limit'])->order(['addtime' => 'desc'])->select();
  144. $count = AgentCustomerLog::where($where)->count();
  145. return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']);
  146. }
  147. /**
  148. * 经济人积分核销列表
  149. */
  150. public function integral_nuclear()
  151. {
  152. $request = request();
  153. $param = $request->param();
  154. $agentid = $param['agentid'];
  155. $agent = AgentUser::where(['id' => $param['agentid'], 'root_id' => $request->employee->root_id])->find();
  156. if (!$agent) {
  157. $data = [
  158. 'all_integral' => 0,
  159. 'already_integral' => 0,
  160. 'ok_integral' => 0,
  161. 'agentid' => $agentid
  162. ];
  163. } else {
  164. $data['all_integral'] = AgentIntegralLog::where([['agt_id', '=', $agentid], ['type', '=', 1]])->sum('integral');
  165. $data['already_integral'] = AgentIntegralLog::where([['agt_id', '=', $agentid], ['type', '=', 2]])->sum('integral');
  166. $data['ok_integral'] = AgentIntegralLog::where([['agt_id', '=', $agentid]])->order('id desc')->value('now_integral');
  167. }
  168. View::assign('data', $data);
  169. return View::fetch();
  170. }
  171. /**
  172. * 经纪人已核销列表
  173. */
  174. public function agent_already_list()
  175. {
  176. $request = request();
  177. $param = $request->param();
  178. $agentid = $param['agentid'];
  179. $agent = AgentUser::where(['id' => $param['agentid'], 'root_id' => $request->employee->root_id])->find();
  180. if (!$agent) return json(['code' => 0, 'data' => [], 'count' => 0, 'msg' => '获取成功']);
  181. $list = AgentIntegralLog::where([['agt_id', '=', $agentid], ['type', '=', 2]])->field('addtime,integral,money')->page($param['page'], $param['limit'])->order(['addtime' => 'desc'])->select()->toArray();
  182. $count = AgentIntegralLog::where([['agt_id', '=', $agentid], ['type', '=', 2]])->count();
  183. return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']);
  184. }
  185. /**
  186. * 经纪人待核销列表
  187. */
  188. public function stay_wiped_list()
  189. {
  190. $request = request();
  191. if (!request()->isAjax()) return View::fetch();
  192. // 列表数据获取
  193. $data = $request->only(['page', 'limit' => 15, 'review_time', 'keyword', 'status']);
  194. // 查询条件设置
  195. $where = [['root_id', '=', $request->employee->root_id]];
  196. if (!empty($data['status'])) $where[] = ['status', '=', $data['status']];
  197. if (empty($data['status'])) $where[] = ['status', 'in', [2, 3, 4]];
  198. if (!empty($data['review_time'])) {
  199. $reviewTime = strtotime($data['review_time']);
  200. $where[] = ['review_time', '>=', $reviewTime];
  201. $where[] = ['review_time', '<', $reviewTime + 86400];
  202. }
  203. $orWhere = [];
  204. if (!empty($data['keyword'])) {
  205. $agtid = AgentUser::where([['root_id', '=', $request->employee->root_id], ['agent_name', 'like', '%' . $data['keyword'] . '%']])->column('id');
  206. $empid = Employee::where([['root_id', '=', $request->employee->root_id], ['name', 'like', '%' . $data['keyword'] . '%']])->column('id');
  207. $where[] = ['agent_id|empid|review_empid', 'in', array_merge($agtid, $empid)];
  208. $orWhere = function ($query) use ($agtid, $empid) {
  209. $query->whereOr([
  210. [['agent_id', 'in', $agtid]],
  211. [['empid', 'in', $empid]],
  212. [['review_empid', 'in', $empid]]
  213. ]);
  214. };
  215. }
  216. $list = AgentApplyIntegral::with(['agent' => function ($query) {
  217. $query->field('id,agent_name,uid,wechat');
  218. }, 'employee' => function ($query) {
  219. $query->field('id,name');
  220. }])->where($where)->where($orWhere)->page($data['page'], $data['limit'])->order('addtime desc')->select()->toArray();
  221. $already_rule = CreditsSetting::where([['code', '=', 'reduce_integral'], ['root_id', '=', $request->employee->root_id]])->value('value');
  222. $already_rule = $already_rule ? json_decode($already_rule, true) : ['jifen' => 1, 'money' => 1];
  223. foreach ($list as $key => $val) {
  224. $list[$key]['agent_headimg'] = User::where('id', $val['agent']['uid'])->value('headimgurl');
  225. $list[$key]['review_name'] = !empty($val['review_empid']) ? Employee::where('id', $val['review_empid'])->value('opt_name') : '';
  226. $list[$key]['review_time'] = date('Y-m-d H:i:s', $val['review_time']);
  227. $list[$key]['good_name'] = !empty($val['good_id']) ? AgentPrize::where([['root_id', '=', $request->employee->root_id], ['id', '=', $val['good_id']]])->value('good_name') : '';
  228. $list[$key]['money'] = !empty($val['integral']) ? bcdiv($val['integral'], $already_rule['jifen'], 1) * $already_rule['money'] : 0;
  229. }
  230. $count = AgentApplyIntegral::where($where)->count();
  231. return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']);
  232. }
  233. /**
  234. * 操作核销经济人积分
  235. */
  236. public function operation_wiped_integral()
  237. {
  238. $request = request();
  239. $data = $request->only(['agentid', 'wiped_integral', 'type', 'id']);
  240. $apply_data = AgentApplyIntegral::where([['root_id', '=', $request->employee->root_id], ['id', '=', $data['id']]])->find();
  241. if (empty($apply_data)) return json(['code' => 1, 'msg' => '数据不存在']);
  242. // 如果是驳回
  243. if (!empty($data['type']) && $data['type'] == 2) {
  244. // 获取当前积分
  245. $agtIntegral = AgentIntegralLog::where([['agt_id', '=', $apply_data['agent_id']]])->order('id desc')->value('now_integral');
  246. $apply_data->status = 4;
  247. $apply_data->review_time = time();
  248. $apply_data->review_empid = $request->employee->id;
  249. $apply_data->save();
  250. // 积分恢复
  251. AgentIntegralLog::create([
  252. 'agt_id' => $apply_data['agent_id'],
  253. 'addtime' => time(),
  254. 'integral' => $apply_data['integral'],
  255. 'type' => 1,
  256. 'now_integral' => $agtIntegral + $apply_data['integral']
  257. ]);
  258. return json(['code' => 0, 'msg' => '驳回成功']);
  259. }
  260. // 审核通过
  261. $apply_data->status = 3;
  262. $apply_data->review_time = time();
  263. $apply_data->review_empid = $request->employee->id;
  264. $apply_data->save();
  265. return json(['code' => 0, 'msg' => '核销成功']);
  266. }
  267. //一键核销
  268. public function all_operation_wiped()
  269. {
  270. $request = request();
  271. $allid = AgentApplyIntegral::where([['root_id', '=', $request->employee->root_id], ['status', '=', 2]])->column('id');
  272. // 更新状态
  273. $save = ['status' => 3, 'review_time' => time(), 'review_empid' => $request->employee->id];
  274. $allid = AgentApplyIntegral::where([['root_id', '=', $request->employee->root_id], ['id', 'in', $allid]])->update($save);
  275. return json(['code' => 0, 'msg' => '核销成功']);
  276. }
  277. /**
  278. * 经纪人数据分析列表
  279. */
  280. public function agent_data_analysis()
  281. {
  282. $request = request();
  283. if (!request()->isAjax()) {
  284. View::assign('employee', $request->employee);
  285. return View::fetch();
  286. }
  287. $where[] = ['status', '=', 1];
  288. $where[] = ['type', '=', $request->param('type')];
  289. $page = $request->param('page') ? $request->param('page') : 1;
  290. $limit = $request->param('limit') ? $request->param('limit') : 10;
  291. $start_date = $request->param('start_date');
  292. $end_date = $request->param('end_date');
  293. if (!empty($start_date) && !empty($end_date)) {
  294. $where[] = ['addtime', '>=', strtotime($start_date)];
  295. $where[] = ['addtime', '<', strtotime($end_date) + 86400];
  296. }
  297. $list = AgentUser::with(['employee' => function ($query) {
  298. $query->field('id,name');
  299. }, 'agenttype' => function ($query) {
  300. $query->field('id,type_name');
  301. }])->where([['root_id', '=', $request->employee->root_id], ['is_review', '=', 2], ['status', '=', 1]])->select()->toArray();
  302. foreach ($list as $key => $val) {
  303. $ph = AgentCustomerLog::where($where)->where('agent_id', $val['id'])->count();
  304. $list[$key]['ph'] = $ph;
  305. $parr[] = $ph;
  306. }
  307. if (!empty($list)) {
  308. array_multisort($parr, SORT_DESC, $list);
  309. }
  310. $count = count($list);
  311. $list = array_slice($list, ($page - 1) * $limit, $limit);
  312. return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']);
  313. }
  314. /**
  315. * 经济人审核列表
  316. */
  317. public function agent_review_list()
  318. {
  319. if (!request()->isAjax()) return View::fetch();
  320. $param = Request::param();
  321. $request = request();
  322. $where[] = ['root_id', '=', $request->employee->root_id];
  323. $list = AgentUser::with(['employee', 'agenttype'])->where($where)->page($param['page'], $param['limit'])->order(['addtime' => 'desc'])->select()->toArray();
  324. foreach ($list as $key => $val) {
  325. if ($val['is_review'] == 1) {
  326. $status = '待审核';
  327. } elseif ($val['is_review'] == 2) {
  328. $status = '通过';
  329. } else {
  330. $status = '未通过';
  331. }
  332. $list[$key]['status'] = $status;
  333. $list[$key]['review_time'] = $val['addtime'];
  334. }
  335. $count = AgentUser::where($where)->count();
  336. return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']);
  337. }
  338. /**
  339. * 奖励规则显示页面
  340. */
  341. public function integral_setting()
  342. {
  343. $request = request();
  344. $type = $request->param('type');
  345. //查询经纪人的类别
  346. $typelist = AgentType::where([['root_id', '=', $request->employee->root_id], ['status', '=', 1]])->select()->toArray();
  347. View::assign('typelist', $typelist);
  348. if ($type == 1) {
  349. return View::fetch();
  350. } else {
  351. return View::fetch('nuclear_setting');
  352. }
  353. }
  354. /**
  355. * 设置积分奖励
  356. */
  357. public function reward_integral_save()
  358. {
  359. $request = request();
  360. $param = Request::only(['daodian', 'jiaoding', 'qiandan', 'hexiao', 'jifen', 'money', 'wanghong', 'putong', 'wjifen', 'wmoney', 'hxtime', 'hxtime_sign', 'ptagentshare', 'whagentshare', 'produceclue', 'measuring_integral', 'measuring_suite_integral', 'measuring_villa_integral', 'qiandan_scale', 'qiandan_money']);
  361. if (isset($param['daodian'])) {
  362. credits($request->employee->root_id, $param['daodian'], 'daodian_integral', 0); //积分
  363. }
  364. if (isset($param['jiaoding'])) {
  365. credits($request->employee->root_id, $param['jiaoding'], 'jiaoding_integral', 0); //贡献值
  366. }
  367. if (isset($param['qiandan'])) {
  368. credits($request->employee->root_id, $param['qiandan'], 'qiandan_integral', 0); //贡献值
  369. }
  370. if (isset($param['qiandan_scale'])) {
  371. credits($request->employee->root_id, $param['qiandan_scale'], 'qiandan_scale_integral', 0); //贡献值
  372. }
  373. if (isset($param['qiandan_money'])) {
  374. credits($request->employee->root_id, $param['qiandan_money'], 'qiandan_money_integral', 0); //贡献值
  375. }
  376. if (isset($param['measuring_integral'])) {
  377. credits($request->employee->root_id, $param['measuring_integral'], 'measuring_integral_integral', 0); //贡献值
  378. }
  379. if (isset($param['measuring_suite_integral'])) {
  380. credits($request->employee->root_id, $param['measuring_suite_integral'], 'measuring_suite_integral_integral', 0); //贡献值
  381. }
  382. if (isset($param['measuring_villa_integral'])) {
  383. credits($request->employee->root_id, $param['measuring_villa_integral'], 'measuring_villa_integral_integral', 0); //贡献值
  384. }
  385. if (isset($param['hxtime'])) {
  386. credits($request->employee->root_id, $param['hxtime'], 'agent_hx_time', 0); //交定核销时间
  387. }
  388. if (isset($param['wanghong'])) {
  389. credits($request->employee->root_id, $param['wanghong'], 'wanghong_integral', 0); //贡献值
  390. }
  391. if (isset($param['jifen']) && isset($param['money'])) {
  392. $json = json_encode(['jifen' => $param['jifen'], 'money' => $param['money']]);
  393. credits($request->employee->root_id, $json, 'reduce_integral', 0); //贡献值
  394. }
  395. if (isset($param['wjifen']) && isset($param['wmoney'])) {
  396. $json = json_encode(['jifen' => $param['wjifen'], 'money' => $param['wmoney']]);
  397. credits($request->employee->root_id, $json, 'wang_reduce_integral', 0); //贡献值
  398. }
  399. if (isset($param['ptagentshare'])) {
  400. credits($request->employee->root_id, $param['ptagentshare'], 'ptagentshare_integral', 0); //积分
  401. }
  402. if (isset($param['whagentshare'])) {
  403. credits($request->employee->root_id, $param['whagentshare'], 'whagentshare_integral', 0); //积分
  404. }
  405. if (isset($param['putong'])) {
  406. credits($request->employee->root_id, $param['putong'], 'putong_integral', 0); //积分
  407. }
  408. if (isset($param['hxtime_sign'])) {
  409. credits($request->employee->root_id, $param['hxtime_sign'], 'agent_hxtime_sign', 0); //签单核销时间
  410. }
  411. if (isset($param['produceclue'])) {
  412. credits($request->employee->root_id, $param['produceclue'], 'produceclue_integral', 0); //签单核销时间
  413. }
  414. return json(['code' => 0, 'msg' => '保存成功']);
  415. }
  416. /**
  417. * 网红经纪人 - 积分设置
  418. */
  419. public function red_integral_setting()
  420. {
  421. return View::fetch();
  422. }
  423. /**
  424. * 设置管理
  425. */
  426. public function set()
  427. {
  428. $request = request();
  429. if (!request()->isAjax()) {
  430. $setdata = Setting::where([['root_id', '=', $request->employee->root_id], ['name', 'in', ['agentInviteShow', 'agentBackgroundImg', 'agentSettingName', 'agentEmployeeAdd']]])->column('content', 'name');
  431. if (empty($setdata)) {
  432. View::assign('img', '');
  433. View::assign('imgs', '');
  434. View::assign('name', '');
  435. View::assign('set_switch', true);
  436. } else {
  437. $oss_url = config('app.ali_oss_bindurl');
  438. $url = !empty($setdata['agentInviteShow']) ? 'https://' . $oss_url . '/' . $setdata['agentInviteShow'] : '';
  439. $urls = !empty($setdata['agentBackgroundImg']) ? 'https://' . $oss_url . '/' . $setdata['agentBackgroundImg'] : '';
  440. View::assign('img', $url);
  441. View::assign('imgs', $urls);
  442. View::assign('name', !empty($setdata['agentSettingName']) ? $setdata['agentSettingName'] : '');
  443. View::assign('set_switch', isset($setdata['agentEmployeeAdd']) ? $setdata['agentEmployeeAdd'] : true);
  444. }
  445. return View::fetch();
  446. }
  447. $data = Request::param(['img', 'imgs', 'name', 'defaults', 'set_switch']);
  448. if (!empty($data['img'])) $this->setsave($request->employee->root_id, $data['img'], 'agentInviteShow');
  449. if (!empty($data['imgs'])) $this->setsave($request->employee->root_id, $data['imgs'], 'agentBackgroundImg');
  450. if (!empty($data['name'])) $this->setsave($request->employee->root_id, $data['name'], 'agentSettingName');
  451. if (!empty($data['defaults'])) $this->setsave($request->employee->root_id, null, 'agentBackgroundImg');
  452. $this->setsave($request->employee->root_id, !isset($data['set_switch']) ? 'false' : 'true', 'agentEmployeeAdd');
  453. return json(['code' => 0, 'msg' => '操作成功']);
  454. }
  455. /**
  456. * 设置表添加方法
  457. */
  458. public function setsave($root_id, $val, $name)
  459. {
  460. $where[] = ['name', '=', $name];
  461. $where[] = ['root_id', '=', $root_id];
  462. $info = Setting::where($where)->find();
  463. if ($info) {
  464. Setting::where($where)->update(['content' => $val]);
  465. } else {
  466. $save['name'] = $name;
  467. $save['root_id'] = $root_id;
  468. $save['content'] = $val;
  469. $save['state'] = 1;
  470. Setting::insert($save);
  471. }
  472. }
  473. /**
  474. * 设置经纪人主题名称
  475. */
  476. public function set_name()
  477. {
  478. $request = request();
  479. if (!request()->isAjax()) {
  480. $name = Setting::where(['root_id' => $request->employee->root_id, 'name' => 'agentSettingName'])->value('content');
  481. View::assign('name', $name);
  482. return View::fetch();
  483. }
  484. $name = Request::param('name');
  485. if (empty($name)) return json(['code' => 1, 'msg' => '请输入名称']);
  486. $set = Setting::where(['root_id' => $request->employee->root_id, 'name' => 'agentSettingName'])->find();
  487. if (!empty($set)) {
  488. $set->content = $name;
  489. $set->save();
  490. } else {
  491. Setting::create([
  492. 'root_id' => $request->employee->root_id,
  493. 'name' => 'agentSettingName',
  494. 'content' => $name,
  495. 'state' => 1
  496. ]);
  497. }
  498. return json(['code' => 0, 'msg' => '操作成功']);
  499. }
  500. /**
  501. * 添加经纪人类别
  502. */
  503. public function add_agenttype()
  504. {
  505. $request = request();
  506. $param = $request->only(['name']);
  507. $add = [
  508. 'type_name' => $param['name'],
  509. 'root_id' => $request->employee->root_id
  510. ];
  511. $ms = AgentType::insertGetId($add);
  512. if ($ms) {
  513. return json(['code' => 0, 'msg' => '添加成功']);
  514. } else {
  515. return json(['code' => 1, 'msg' => '添加失败']);
  516. }
  517. }
  518. /**
  519. * 修改经纪人类别
  520. */
  521. public function edit_agenttype()
  522. {
  523. $request = request();
  524. $param = $request->only(['id', 'name']);
  525. $data = AgentType::where([['root_id', '=', $request->employee->root_id], ['id', '=', $param['id']]])->find();
  526. if (empty($data)) return json(['code' => 1, 'msg' => '数据不存在']);
  527. $data->type_name = $param['name'];
  528. $ms = $data->save();
  529. if ($ms) {
  530. return json(['code' => 0, 'msg' => '修改成功']);
  531. } else {
  532. return json(['code' => 1, 'msg' => '修改失败']);
  533. }
  534. }
  535. /**
  536. * 删除经纪人类别
  537. */
  538. public function del_agenttype()
  539. {
  540. $request = request();
  541. $param = $request->only(['id']);
  542. $data = AgentType::where([['root_id', '=', $request->employee->root_id], ['id', '=', $param['id']]])->find();
  543. if (empty($data)) return json(['code' => 1, 'msg' => '数据不存在']);
  544. $check = AgentUser::where([['root_id', '=', $request->employee->root_id], ['type', '=', $data['id']]])->count();
  545. if (!empty($check)) return json(['code' => 1, 'msg' => '当前类别下有经纪人,不能删除']);
  546. //判断最后一个不能删除
  547. $last = AgentType::where([['root_id', '=', $request->employee->root_id], ['status', '=', 1]])->count();
  548. if ($last == 1) return json(['code' => 1, 'msg' => '最后一个类别,不能删除']);
  549. $ms = $data->delete();
  550. if ($ms) {
  551. return json(['code' => 0, 'msg' => '删除成功']);
  552. } else {
  553. return json(['code' => 1, 'msg' => '删除失败']);
  554. }
  555. }
  556. /**
  557. * 获取当前类别
  558. */
  559. public function get_agentrule()
  560. {
  561. $request = request();
  562. $param = $request->only(['id']);
  563. $data = AgentType::where([['root_id', '=', $request->employee->root_id], ['id', '=', $param['id']]])->find();
  564. if (empty($data)) return json(['code' => 1, 'msg' => '数据不存在']);
  565. $data['count'] = json_decode($data['count']);
  566. return json(['code' => 0, 'data' => $data, 'msg' => '获取成功']);
  567. }
  568. /**
  569. * 设置类别的规则
  570. */
  571. public function set_agentrule()
  572. {
  573. $request = request();
  574. $param = Request::only(['id', 'daodian' => '', 'jiaoding' => '', 'qiandan' => '', 'putong' => '', 'hxtime' => '', 'hxtime_sign' => '', 'ptagentshare' => '', 'produceclue' => '', 'measuring' => '', 'measuring_suite' => '', 'measuring_villa' => '', 'qiandan_scale' => '', 'qiandan_money' => '']);
  575. $content = [
  576. 'daodian_integral' => $param['daodian'],
  577. 'measuring_integral' => $param['measuring'],
  578. 'measuring_suite_integral' => $param['measuring_suite'],
  579. 'measuring_villa_integral' => $param['measuring_villa'],
  580. 'jiaoding_integral' => $param['jiaoding'],
  581. 'qiandan_integral' => $param['qiandan'],
  582. 'qiandan_scale_integral' => $param['qiandan_scale'],
  583. 'qiandan_money_integral' => $param['qiandan_money'],
  584. 'ptagentshare_integral' => $param['ptagentshare'],
  585. 'putong_integral' => $param['putong'],
  586. 'agent_hxtime_sign' => $param['hxtime_sign'],
  587. 'agent_hx_time' => $param['hxtime'],
  588. 'produceclue_integral' => $param['produceclue']
  589. ];
  590. $data = AgentType::where([['root_id', '=', $request->employee->root_id], ['id', '=', $param['id']]])->find();
  591. if (empty($data)) return json(['code' => 1, 'msg' => '数据不存在']);
  592. $data->count = json_encode($content);
  593. $ms = $data->save();
  594. return json(['code' => 0, 'msg' => '设置成功']);
  595. }
  596. /**
  597. * 设置奖品
  598. */
  599. public function prize_setting()
  600. {
  601. $request = request();
  602. $root_id = $request->employee->root_id;
  603. if (!request()->isAjax()) {
  604. $list = AgentPrize::where([['root_id', '=', $root_id], ['status', '=', 1]])->select()->toArray();
  605. View::assign('list', $list);
  606. $where[] = ['code', '=', 'reduce_integral'];
  607. $where[] = ['root_id', '=', $request->employee->root_id];
  608. $person2 = CreditsSetting::where($where)->value('value');
  609. $data['reduce_integral'] = $person2 ? json_decode($person2, true) : ['jifen' => 1, 'money' => 0];
  610. View::assign('data', $data);
  611. return View::fetch();
  612. }
  613. }
  614. /**
  615. * 添加奖品
  616. */
  617. public function add_prize()
  618. {
  619. $request = request();
  620. $param = $request->only(['name', 'integral', 'img' => '']);
  621. if (!request()->isAjax()) {
  622. return View::fetch();
  623. }
  624. $add = [
  625. 'good_name' => $param['name'],
  626. 'root_id' => $request->employee->root_id,
  627. 'integral' => $param['integral'],
  628. 'img' => $param['img']
  629. ];
  630. $ms = AgentPrize::insertGetId($add);
  631. if ($ms) {
  632. return json(['code' => 0, 'msg' => '添加成功']);
  633. } else {
  634. return json(['code' => 1, 'msg' => '添加失败']);
  635. }
  636. }
  637. /**
  638. * 修改奖品
  639. */
  640. public function edit_prize()
  641. {
  642. $request = request();
  643. $param = $request->only(['id', 'name', 'integral', 'img' => '']);
  644. $data = AgentPrize::where([['root_id', '=', $request->employee->root_id], ['id', '=', $param['id']]])->find();
  645. if (empty($data)) return json(['code' => 1, 'msg' => '数据不存在']);
  646. if (!request()->isAjax()) {
  647. View::assign('data', $data);
  648. return View::fetch();
  649. }
  650. $data->good_name = $param['name'];
  651. if (!empty($param['img'])) $data->img = $param['img'];
  652. $data->integral = $param['integral'];
  653. $data->save();
  654. return json(['code' => 0, 'msg' => '修改成功']);
  655. }
  656. /**
  657. * 删除奖品
  658. */
  659. public function del_prize()
  660. {
  661. $request = request();
  662. $param = $request->only(['id']);
  663. $data = AgentPrize::where([['root_id', '=', $request->employee->root_id], ['id', '=', $param['id']]])->find();
  664. if (empty($data)) return json(['code' => 1, 'msg' => '数据不存在']);
  665. $ms = $data->delete();
  666. if ($ms) {
  667. return json(['code' => 0, 'msg' => '删除成功']);
  668. } else {
  669. return json(['code' => 1, 'msg' => '删除失败']);
  670. }
  671. }
  672. /**
  673. * 经纪人内容管理
  674. */
  675. public function agent_article_list()
  676. {
  677. $request = request();
  678. $param = $request->only(['id', 'title', 'employee_id', 'from' => 2, 'add_time', 'page' => 1, 'limit' => 10]);
  679. if (!request()->isAjax()) {
  680. $employee = Employee::where([['root_id', '=', $request->employee->root_id], ['state', '=', '在职']])->column('id,name');
  681. View::assign('employee', $employee);
  682. return View::fetch();
  683. }
  684. //var_dump($param['from']);exit;
  685. $where[] = ['root_id', '=', $request->employee->root_id];
  686. $where[] = ['from', '=', $param['from']];
  687. if (!empty($param['title'])) $where[] = ['title', 'like', '%' . $param['title'] . '%'];
  688. if (!empty($param['employee_id'])) $where[] = ['employee_id', '=', $param['employee_id']];
  689. if (!empty($param['add_time'])) {
  690. $time = explode(' - ', $param['add_time']);
  691. $where[] = ['addtime', 'between', [$time[0], $time[1]]];
  692. }
  693. $list = AgentArticle::with(['employee' => function ($query) {
  694. $query->field('id,name,opt_name');
  695. }])->where($where)->order('addtime desc')->page($param['page'], $param['limit'])->select()->toArray();
  696. $vrObj = new Vr();
  697. foreach ($list as $key => $val) {
  698. if ($val['type'] == 1) $list[$key]['file_img'] = $val['cover'];
  699. if ($val['type'] == 2) $list[$key]['file_img'] = !empty($val['file'][0]) ? $val['file'][0] : '';
  700. if ($val['type'] == 3) $list[$key]['file_img'] = !empty($val['file'][0]) ? $vrObj->getFirstImg(str_replace('https://' . config('app.ali_oss_bindurl') . '/', '', $val['file'][0])) : '';
  701. if ($val['type'] == 4) {
  702. $group = VrGroup::where('id', $val['vr_group_ids'])->field('pic_path')->findOrEmpty();
  703. $list[$key]['file_img'] = $group->isEmpty() ? '' : $group->pic_path;
  704. }
  705. }
  706. $count = AgentArticle::where($where)->count();
  707. return json(['code' => 0, 'msg' => '获取成功', 'data' => $list, 'count' => $count]);
  708. }
  709. /**
  710. * 单独查询数据
  711. */
  712. public function sel_artdata($list, $emplist, $root_id)
  713. {
  714. foreach ($list as &$item) {
  715. $item['employee'] = !empty($emplist[$item['employee_id']]) ? $emplist[$item['employee_id']] : '';
  716. switch ($item['type']) {
  717. case 'Article':
  718. $find = Article::where([
  719. ['root_id', '=', $root_id],
  720. ['delete_time', '=', 0],
  721. ['publish', '=', 1],
  722. ['id', '=', $item['data_id']]
  723. ])->field('id,title,cover_img')->find();
  724. $item['content_id'] = !empty($find['id']) ? $find['id'] : 0;
  725. $item['title'] = !empty($find['title']) ? $find['title'] : '';
  726. $item['file_img'] = !empty($find['cover_img']) ? $find['cover_img'] : '';
  727. break;
  728. case 'MaterialCase':
  729. $find = MaterialCase::where([
  730. ['root_id', '=', $root_id],
  731. ['del', '=', 0],
  732. ['publish', '=', 1],
  733. ['id', '=', $item['data_id']]
  734. ])->field('id,title,cover_img')->find();
  735. $item['content_id'] = !empty($find['id']) ? $find['id'] : 0;
  736. $item['title'] = !empty($find['title']) ? $find['title'] : '';
  737. $item['file_img'] = !empty($find['cover_img']) ? $find['cover_img'] : '';
  738. break;
  739. case 'Video':
  740. $find = Video::where([
  741. ['root_id', '=', $root_id],
  742. ['delete_time', '=', 0],
  743. ['publish', '=', 1],
  744. ['id', '=', $item['data_id']]
  745. ])->field('id,title,video_url')->find();
  746. $item['content_id'] = !empty($find['id']) ? $find['id'] : 0;
  747. $item['title'] = !empty($find['title']) ? $find['title'] : '';
  748. $item['file_img'] = !empty($find['video_url']) ? $find['video_url'] : '';
  749. $item['file_type'] = 1;
  750. break;
  751. case 'CompanyStrength':
  752. $find = CompanyStrength::where([
  753. ['root_id', '=', $root_id],
  754. ['del', '=', 0],
  755. ['publish', '=', 1],
  756. ['id', '=', $item['data_id']]
  757. ])->field('id,title,pics,difference')->find();
  758. $item['content_id'] = !empty($find['id']) ? $find['id'] : 0;
  759. $item['title'] = !empty($find['title']) ? $find['title'] : '';
  760. $item['file_img'] = !empty($find['pics']) ? $find['pics'] : '';
  761. $item['difference'] = !empty($find['difference']) ? $find['difference'] : '';
  762. break;
  763. case 'MaterialEvidence':
  764. $find = MaterialEvidence::where([
  765. ['root_id', '=', $root_id],
  766. ['del', '=', 0],
  767. ['publish', '=', 1],
  768. ['id', '=', $item['data_id']]
  769. ])->field('id,title,pics,difference')->find();
  770. $item['content_id'] = !empty($find['id']) ? $find['id'] : 0;
  771. $item['title'] = !empty($find['title']) ? $find['title'] : '';
  772. $item['file_img'] = !empty($find['pics'][0]) ? $find['pics'][0] : '';
  773. $item['difference'] = !empty($find['difference']) ? $find['difference'] : '';
  774. break;
  775. case 'Building':
  776. $find = Building::where([
  777. ['root_id', '=', $root_id],
  778. ['del', '=', 0],
  779. ['id', '=', $item['data_id']]
  780. ])->field('id,community_id,name,cover')->find();
  781. $item['content_id'] = !empty($find['id']) ? $find['id'] : 0;
  782. $item['title'] = !empty($find['name']) ? $find['name'] : '';
  783. $item['file_img'] = !empty($find['cover'][0]) ? $find['cover'][0] : '';
  784. break;
  785. case 'AgentArticle':
  786. $find = AgentArticle::where([
  787. ['root_id', '=', $root_id],
  788. ['id', '=', $item['data_id']]
  789. ])->field('id,title,file,type')->find();
  790. $item['content_id'] = !empty($find['id']) ? $find['id'] : 0;
  791. $item['title'] = !empty($find['title']) ? $find['title'] : '';
  792. $file = !empty($find['file'][0]) ? $find['file'][0] : '';
  793. $item['file_img'] = !empty($find['file'][0]) ? $find['file'][0] : '';
  794. $item['file_type'] = !empty($find['type']) ? $find['type'] : 0;
  795. break;
  796. default:
  797. $item['content_id'] = 0;
  798. $item['title'] = '';
  799. $item['file_img'] = '';
  800. break;
  801. }
  802. }
  803. return $list;
  804. }
  805. /**
  806. * 员工分享列表
  807. */
  808. public function agtemp_artlist()
  809. {
  810. $request = request();
  811. $root_id = $request->employee->root_id;
  812. $param = $request->only(['id', 'title', 'employee_id', 'add_time', 'page' => 1, 'limit' => 10]);
  813. $where[] = ['root_id', '=', $root_id];
  814. if (!empty($param['employee_id'])) $where[] = ['employee_id', '=', $param['employee_id']];
  815. if (!empty($param['add_time'])) {
  816. $time = explode(' - ', $param['add_time']);
  817. $where[] = ['addtime', 'between', [$time[0], $time[1]]];
  818. }
  819. if (!empty($param['title'])) {
  820. $list = AgentShareContent::where($where)->column('id,type,employee_id,data_id');
  821. $emplist = [];
  822. $titlist = $this->sel_artdata($list, $emplist, $root_id);
  823. foreach ($titlist as $v) {
  824. if (strpos(trim($v['title']), $param['title']) !== false) $selid[] = $v['id'];
  825. }
  826. $where[] = ['id', 'in', $selid];
  827. }
  828. $list = AgentShareContent::where($where)->page($param['page'], $param['limit'])->order('addtime desc')->select()->toArray();
  829. $emplist = Employee::where([['root_id', '=', $root_id], ['id', 'in', array_column($list, 'employee_id')]])->column('name,opt_name', 'id');
  830. $list = $this->sel_artdata($list, $emplist, $root_id);
  831. $count = AgentShareContent::where($where)->count();
  832. return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']);
  833. }
  834. /**
  835. * 添加内容
  836. */
  837. public function add_article()
  838. {
  839. $request = request();
  840. $param = $request->only(['title', 'type', 'covers' => '', 'desc', 'video_url' => '', 'vrurl' => '', 'cover' => '', 'vr_group_ids' => '']);
  841. if (!request()->isAjax()) {
  842. return View::fetch();
  843. }
  844. $file = '';
  845. if ($param['type'] == 1) $file = $param['video_url'];
  846. if ($param['type'] == 2) $file = $param['covers'];
  847. if ($param['type'] == 3) $file = $param['vrurl'];
  848. $add = [
  849. 'title' => $param['title'],
  850. 'type' => $param['type'],
  851. 'cover' => $param['cover'],
  852. 'file' => $file,
  853. 'content' => $param['desc'],
  854. 'employee_id' => $request->employee->id,
  855. 'root_id' => $request->employee->root_id,
  856. 'from' => 2,
  857. 'addtime' => time(),
  858. 'vr_group_ids' => $param['vr_group_ids']
  859. ];
  860. $ms = AgentArticle::create($add);
  861. AgentShareContent::create(['root_id' => $request->employee->root_id, 'employee_id' => $request->employee->id, 'data_id' => $ms->id, 'type' => 'AgentArticle','from'=>2]);
  862. if ($ms) {
  863. return json(['code' => 0, 'msg' => '添加成功']);
  864. } else {
  865. return json(['code' => 1, 'msg' => '添加失败']);
  866. }
  867. }
  868. /**
  869. * 开启文章
  870. */
  871. public function apipublish()
  872. {
  873. $request = request();
  874. $param = $request->only(['id']);
  875. $data = AgentArticle::where([['root_id', '=', $request->employee->root_id], ['id', '=', $param['id']]])->find();
  876. if (empty($data)) return json(['code' => '1', 'msg' => '数据不存在']);
  877. $data->disable = $data->disable == 0 ? 1 : 0;
  878. $ms = $data->save();
  879. if ($ms) {
  880. return json(['code' => 0, 'msg' => '修改成功']);
  881. } else {
  882. return json(['code' => 1, 'msg' => '修改失败']);
  883. }
  884. }
  885. /*
  886. * 富文本图片
  887. */
  888. public function imgUpload()
  889. {
  890. $bindUrl = config('app.ali_oss_bindurl');
  891. $data = [
  892. 'src' => 'https://' . $bindUrl . '/' . Request::param('file'),
  893. 'title' => ''
  894. ];
  895. return json(['code' => 0, 'msg' => '', 'data' => $data]);
  896. }
  897. /**
  898. * 编辑文章
  899. */
  900. public function edit_article()
  901. {
  902. $request = request();
  903. $param = $request->only(['id', 'title', 'type', 'covers' => '', 'desc', 'video_url' => '', 'vrurl' => '', 'cover' => '', 'oldcovers' => '', 'vr_group_ids' => '']);
  904. $data = AgentArticle::where([['root_id', '=', $request->employee->root_id], ['id', '=', $param['id']]])->find();
  905. if (empty($data)) return json(['code' => 1, 'msg' => '数据不存在']);
  906. if (!request()->isAjax()) {
  907. if (!empty($data)) {
  908. $data['fileuri'] = $data['covers'] = $data['vrurl'] = '';
  909. if ($data['type'] == 1) $data['fileuri'] = !empty($data['file']) ? $data['file'][0] : '';
  910. if ($data['type'] == 2) $data['covers'] = !empty($data['file']) ? $data['file'] : [];
  911. if ($data['type'] == 3) $data['vrurl'] = !empty($data['file']) ? str_replace('https://' . config('app.ali_oss_bindurl') . '/', '', $data['file'][0]) : '';
  912. $data['oldfile'] = $data->getData('file');
  913. $data['group_name'] = $data['vr_group_ids'] ? (VrGroup::where('id', $data['vr_group_ids'])->value('title') ?: '未命名作品') : '未命名作品';
  914. }
  915. View::assign('data', $data);
  916. return View::fetch();
  917. }
  918. if (!empty($param['oldcovers'])) {
  919. $param['covers'] = trim(implode(',', $param['oldcovers']) . ',' . $param['covers'], ',');
  920. }
  921. //var_dump($param);exit;
  922. $file = '';
  923. if ($param['type'] == 1) $file = $param['video_url'];
  924. if ($param['type'] == 2) $file = $param['covers'];
  925. if ($param['type'] == 3) $file = $param['vrurl'];
  926. //$data->cover = !empty($param['cover']) ? $param['cover'] : $param['oldcover'];
  927. $data->cover = $param['cover'];
  928. $data->title = $param['title'];
  929. $data->type = $param['type'];
  930. $data->file = $file;
  931. $data->content = $param['desc'];
  932. $data->vr_group_ids = $param['vr_group_ids'];
  933. $ms = $data->save();
  934. if ($ms) {
  935. return json(['code' => 0, 'msg' => '修改成功']);
  936. } else {
  937. return json(['code' => 1, 'msg' => '修改失败']);
  938. }
  939. }
  940. /**
  941. * 删除文章
  942. */
  943. public function del_article()
  944. {
  945. $request = request();
  946. $param = $request->only(['id', 'title', 'type', 'covers' => '', 'desc', 'fileuri' => '', 'vrurl' => '']);
  947. $data = AgentArticle::where([['root_id', '=', $request->employee->root_id], ['id', '=', $param['id']]])->find();
  948. if (empty($data)) return json(['code' => 1, 'msg' => '数据不存在']);
  949. $ms = $data->delete();
  950. if ($ms) {
  951. return json(['code' => 0, 'msg' => '删除成功']);
  952. } else {
  953. return json(['code' => 1, 'msg' => '删除失败']);
  954. }
  955. }
  956. }