123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014 |
- <?php
- namespace app\sys\controller;
- use think\facade\View;
- use app\model\Customer;
- use app\model\Employee;
- use app\model\CreditsSetting;
- use think\facade\Request;
- use app\model\AgentUser;
- use app\model\AgentIntegralLog;
- use app\model\AgentCustomerLog;
- use app\model\AgentIntegral;
- use app\model\Setting;
- use app\model\AgentApplyIntegral;
- use app\model\AgentArticle;
- use app\model\User;
- use app\model\AgentType;
- use app\model\AgentPrize;
- use app\model\AgentShareContent;
- use xiaohongwu\Vr;
- use app\model\Article;
- use app\model\MaterialCase;
- use app\model\Video;
- use app\model\CompanyStrength;
- use app\model\MaterialEvidence;
- use app\model\Building;
- use app\model\VrGroup;
- class Agents
- {
- /**
- * 经济人列表
- */
- public function agent_list()
- {
- $param = Request::param();
- $request = request();
- if (!request()->isAjax()) {
- //查询是否有需要核销的积分
- $is_review = AgentApplyIntegral::where([['root_id', '=', $request->employee->root_id], ['status', '=', 2]])->count();
- View::assign('is_review', $is_review);
- View::assign('employee', $request->employee);
- return View::fetch();
- }
- $where = [['root_id', '=', $request->employee->root_id]];
- if (!empty($param['keyword'])) {
- $empid = Employee::where([['name', 'like', $param['keyword'] . '%'], ['root_id', '=', $request->employee->root_id]])->field('id,name')->column('id');
- $where[] = ['agent_employee_id', 'in', $empid];
- }
- $list = AgentUser::with(['employee', 'agenttype'])
- ->withCount('customer')
- ->where($where)->page($param['page'], $param['limit'])
- ->order(['addtime' => 'desc'])
- ->select()
- ->toArray();
- foreach ($list as $key => $val) {
- $list[$key]['daodiannum'] = AgentCustomerLog::where([['agent_id', '=', $val['id']], ['status', '=', 1], ['type', '=', 1]])->count();
- $list[$key]['jiaodingnum'] = AgentCustomerLog::where([['agent_id', '=', $val['id']], ['status', '=', 1], ['type', '=', 2]])->count();
- $list[$key]['qiandannum'] = AgentCustomerLog::where([['agent_id', '=', $val['id']], ['status', '=', 1], ['type', '=', 3]])->count();
- $list[$key]['now_integral'] = AgentIntegralLog::where('agt_id', $val['id'])->order('id desc')->value('now_integral');
- }
- $count = AgentUser::where($where)->count();
- return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']);
- }
- /**
- * 修改经纪人账号状态
- */
- public function up_agt_accnumb()
- {
- $request = request();
- $param = $request->param();
- $ms = Agentuser::where([['id', '=', $param['id']], ['root_id', '=', $request->employee->root_id]])->find();
- $ms->status = $ms->status == 1 ? 2 : 1;
- $ms->save();
- if (!$ms) return json(['code' => 0, 'msg' => '修改失败']);
- return json(['code' => 0, 'msg' => '修改成功']);
- }
- /**
- * 经济人客户列表明细
- */
- public function agent_customer_list()
- {
- $request = request();
- // 页面展示
- if (!request()->isAjax()) {
- $param = Request::param();
- $agentid = $param['agentid'];
- View::assign('employee', $request->employee);
- View::assign('agentid', $agentid);
- return View::fetch();
- }
- // 数据请求
- $param = $request->param();
- // 检测经纪人是否存在
- $agent = AgentUser::where(['id' => $param['agentid'], 'root_id' => $request->employee->root_id])->find();
- if (empty($agent)) return json(['code' => 0, 'data' => [], 'count' => 0, 'msg' => '获取成功']);
- $where = [['agents_id', '=', $param['agentid']]];
- $list = Customer::with(['agentLog'])->where($where)->field('id,name,addtime')->page($param['page'], $param['limit'])->order(['addtime' => 'desc'])->select()->toArray();
- foreach ($list as $key => $val) {
- $all_integral = AgentIntegral::where([['customer_id', '=', $val['id']], ['status', '<>', 3]])->sum('integral');
- $list[$key]['all_integral'] = $all_integral;
- $daodiantime = $jiaodingtime = $qiandantime = 0;
- foreach ($val['agentLog'] as $v) {
- if ($v['type'] == 1) {
- $daodiantime = date('Y-m-d', strtotime($v['addtime']));
- }
- if ($v['type'] == 2) {
- $jiaodingtime = date('Y-m-d', strtotime($v['addtime']));
- }
- if ($v['type'] == 3) {
- $qiandantime = date('Y-m-d', strtotime($v['addtime']));
- }
- }
- $list[$key]['daodiantime'] = $daodiantime ? $daodiantime : 0;
- $list[$key]['qiandantime'] = $qiandantime ? $qiandantime : 0;
- $list[$key]['jiaodingtime'] = $jiaodingtime ? $jiaodingtime : 0;
- $list[$key]['employee'] = $request->employee; //加入后台操作人员信息判断馨居尚
- }
- $count = Customer::where($where)->count();
- return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']);
- }
- /**
- * 到访明细
- */
- public function agent_kehu_list()
- {
- $request = request();
- $param = $request->param();
- if (!request()->isAjax()) {
- $type = $param['type'];
- $agentid = $param['agentid'];
- View::assign('agentid', $agentid);
- View::assign('employee', $request->employee);
- if ($type == 1) return View::fetch('visit_number');
- if ($type == 2) return View::fetch('deposit_people');
- if ($type == 3) return View::fetch('sign_people');
- }
- $agent = AgentUser::where(['id' => $param['agentid'], 'root_id' => $request->employee->root_id])->find();
- if (!$agent) return json(['code' => 0, 'data' => [], 'count' => 0, 'msg' => '获取成功']);
- $where = [
- ['status', '=', 1],
- ['type', '=', $param['type']],
- ['agent_id', '=', $param['agentid']]
- ];
- $list = AgentCustomerLog::with(['customer'])->where($where)->page($param['page'], $param['limit'])->order(['addtime' => 'desc'])->select();
- $count = AgentCustomerLog::where($where)->count();
- return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']);
- }
- /**
- * 经济人积分核销列表
- */
- public function integral_nuclear()
- {
- $request = request();
- $param = $request->param();
- $agentid = $param['agentid'];
- $agent = AgentUser::where(['id' => $param['agentid'], 'root_id' => $request->employee->root_id])->find();
- if (!$agent) {
- $data = [
- 'all_integral' => 0,
- 'already_integral' => 0,
- 'ok_integral' => 0,
- 'agentid' => $agentid
- ];
- } else {
- $data['all_integral'] = AgentIntegralLog::where([['agt_id', '=', $agentid], ['type', '=', 1]])->sum('integral');
- $data['already_integral'] = AgentIntegralLog::where([['agt_id', '=', $agentid], ['type', '=', 2]])->sum('integral');
- $data['ok_integral'] = AgentIntegralLog::where([['agt_id', '=', $agentid]])->order('id desc')->value('now_integral');
- }
- View::assign('data', $data);
- return View::fetch();
- }
- /**
- * 经纪人已核销列表
- */
- public function agent_already_list()
- {
- $request = request();
- $param = $request->param();
- $agentid = $param['agentid'];
- $agent = AgentUser::where(['id' => $param['agentid'], 'root_id' => $request->employee->root_id])->find();
- if (!$agent) return json(['code' => 0, 'data' => [], 'count' => 0, 'msg' => '获取成功']);
- $list = AgentIntegralLog::where([['agt_id', '=', $agentid], ['type', '=', 2]])->field('addtime,integral,money')->page($param['page'], $param['limit'])->order(['addtime' => 'desc'])->select()->toArray();
- $count = AgentIntegralLog::where([['agt_id', '=', $agentid], ['type', '=', 2]])->count();
- return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']);
- }
- /**
- * 经纪人待核销列表
- */
- public function stay_wiped_list()
- {
- $request = request();
- if (!request()->isAjax()) return View::fetch();
- // 列表数据获取
- $data = $request->only(['page', 'limit' => 15, 'review_time', 'keyword', 'status']);
- // 查询条件设置
- $where = [['root_id', '=', $request->employee->root_id]];
- if (!empty($data['status'])) $where[] = ['status', '=', $data['status']];
- if (empty($data['status'])) $where[] = ['status', 'in', [2, 3, 4]];
- if (!empty($data['review_time'])) {
- $reviewTime = strtotime($data['review_time']);
- $where[] = ['review_time', '>=', $reviewTime];
- $where[] = ['review_time', '<', $reviewTime + 86400];
- }
- $orWhere = [];
- if (!empty($data['keyword'])) {
- $agtid = AgentUser::where([['root_id', '=', $request->employee->root_id], ['agent_name', 'like', '%' . $data['keyword'] . '%']])->column('id');
- $empid = Employee::where([['root_id', '=', $request->employee->root_id], ['name', 'like', '%' . $data['keyword'] . '%']])->column('id');
- $where[] = ['agent_id|empid|review_empid', 'in', array_merge($agtid, $empid)];
- $orWhere = function ($query) use ($agtid, $empid) {
- $query->whereOr([
- [['agent_id', 'in', $agtid]],
- [['empid', 'in', $empid]],
- [['review_empid', 'in', $empid]]
- ]);
- };
- }
- $list = AgentApplyIntegral::with(['agent' => function ($query) {
- $query->field('id,agent_name,uid,wechat');
- }, 'employee' => function ($query) {
- $query->field('id,name');
- }])->where($where)->where($orWhere)->page($data['page'], $data['limit'])->order('addtime desc')->select()->toArray();
- $already_rule = CreditsSetting::where([['code', '=', 'reduce_integral'], ['root_id', '=', $request->employee->root_id]])->value('value');
- $already_rule = $already_rule ? json_decode($already_rule, true) : ['jifen' => 1, 'money' => 1];
- foreach ($list as $key => $val) {
- $list[$key]['agent_headimg'] = User::where('id', $val['agent']['uid'])->value('headimgurl');
- $list[$key]['review_name'] = !empty($val['review_empid']) ? Employee::where('id', $val['review_empid'])->value('opt_name') : '';
- $list[$key]['review_time'] = date('Y-m-d H:i:s', $val['review_time']);
- $list[$key]['good_name'] = !empty($val['good_id']) ? AgentPrize::where([['root_id', '=', $request->employee->root_id], ['id', '=', $val['good_id']]])->value('good_name') : '';
- $list[$key]['money'] = !empty($val['integral']) ? bcdiv($val['integral'], $already_rule['jifen'], 1) * $already_rule['money'] : 0;
- }
- $count = AgentApplyIntegral::where($where)->count();
- return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']);
- }
- /**
- * 操作核销经济人积分
- */
- public function operation_wiped_integral()
- {
- $request = request();
- $data = $request->only(['agentid', 'wiped_integral', 'type', 'id']);
- $apply_data = AgentApplyIntegral::where([['root_id', '=', $request->employee->root_id], ['id', '=', $data['id']]])->find();
- if (empty($apply_data)) return json(['code' => 1, 'msg' => '数据不存在']);
- // 如果是驳回
- if (!empty($data['type']) && $data['type'] == 2) {
- // 获取当前积分
- $agtIntegral = AgentIntegralLog::where([['agt_id', '=', $apply_data['agent_id']]])->order('id desc')->value('now_integral');
- $apply_data->status = 4;
- $apply_data->review_time = time();
- $apply_data->review_empid = $request->employee->id;
- $apply_data->save();
- // 积分恢复
- AgentIntegralLog::create([
- 'agt_id' => $apply_data['agent_id'],
- 'addtime' => time(),
- 'integral' => $apply_data['integral'],
- 'type' => 1,
- 'now_integral' => $agtIntegral + $apply_data['integral']
- ]);
- return json(['code' => 0, 'msg' => '驳回成功']);
- }
- // 审核通过
- $apply_data->status = 3;
- $apply_data->review_time = time();
- $apply_data->review_empid = $request->employee->id;
- $apply_data->save();
- return json(['code' => 0, 'msg' => '核销成功']);
- }
- //一键核销
- public function all_operation_wiped()
- {
- $request = request();
- $allid = AgentApplyIntegral::where([['root_id', '=', $request->employee->root_id], ['status', '=', 2]])->column('id');
- // 更新状态
- $save = ['status' => 3, 'review_time' => time(), 'review_empid' => $request->employee->id];
- $allid = AgentApplyIntegral::where([['root_id', '=', $request->employee->root_id], ['id', 'in', $allid]])->update($save);
- return json(['code' => 0, 'msg' => '核销成功']);
- }
- /**
- * 经纪人数据分析列表
- */
- public function agent_data_analysis()
- {
- $request = request();
- if (!request()->isAjax()) {
- View::assign('employee', $request->employee);
- return View::fetch();
- }
- $where[] = ['status', '=', 1];
- $where[] = ['type', '=', $request->param('type')];
- $page = $request->param('page') ? $request->param('page') : 1;
- $limit = $request->param('limit') ? $request->param('limit') : 10;
- $start_date = $request->param('start_date');
- $end_date = $request->param('end_date');
- if (!empty($start_date) && !empty($end_date)) {
- $where[] = ['addtime', '>=', strtotime($start_date)];
- $where[] = ['addtime', '<', strtotime($end_date) + 86400];
- }
- $list = AgentUser::with(['employee' => function ($query) {
- $query->field('id,name');
- }, 'agenttype' => function ($query) {
- $query->field('id,type_name');
- }])->where([['root_id', '=', $request->employee->root_id], ['is_review', '=', 2], ['status', '=', 1]])->select()->toArray();
- foreach ($list as $key => $val) {
- $ph = AgentCustomerLog::where($where)->where('agent_id', $val['id'])->count();
- $list[$key]['ph'] = $ph;
- $parr[] = $ph;
- }
- if (!empty($list)) {
- array_multisort($parr, SORT_DESC, $list);
- }
- $count = count($list);
- $list = array_slice($list, ($page - 1) * $limit, $limit);
- return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']);
- }
- /**
- * 经济人审核列表
- */
- public function agent_review_list()
- {
- if (!request()->isAjax()) return View::fetch();
- $param = Request::param();
- $request = request();
- $where[] = ['root_id', '=', $request->employee->root_id];
- $list = AgentUser::with(['employee', 'agenttype'])->where($where)->page($param['page'], $param['limit'])->order(['addtime' => 'desc'])->select()->toArray();
- foreach ($list as $key => $val) {
- if ($val['is_review'] == 1) {
- $status = '待审核';
- } elseif ($val['is_review'] == 2) {
- $status = '通过';
- } else {
- $status = '未通过';
- }
- $list[$key]['status'] = $status;
- $list[$key]['review_time'] = $val['addtime'];
- }
- $count = AgentUser::where($where)->count();
- return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']);
- }
- /**
- * 奖励规则显示页面
- */
- public function integral_setting()
- {
- $request = request();
- $type = $request->param('type');
- //查询经纪人的类别
- $typelist = AgentType::where([['root_id', '=', $request->employee->root_id], ['status', '=', 1]])->select()->toArray();
- View::assign('typelist', $typelist);
- if ($type == 1) {
- return View::fetch();
- } else {
- return View::fetch('nuclear_setting');
- }
- }
- /**
- * 设置积分奖励
- */
- public function reward_integral_save()
- {
- $request = request();
- $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']);
- if (isset($param['daodian'])) {
- credits($request->employee->root_id, $param['daodian'], 'daodian_integral', 0); //积分
- }
- if (isset($param['jiaoding'])) {
- credits($request->employee->root_id, $param['jiaoding'], 'jiaoding_integral', 0); //贡献值
- }
- if (isset($param['qiandan'])) {
- credits($request->employee->root_id, $param['qiandan'], 'qiandan_integral', 0); //贡献值
- }
- if (isset($param['qiandan_scale'])) {
- credits($request->employee->root_id, $param['qiandan_scale'], 'qiandan_scale_integral', 0); //贡献值
- }
- if (isset($param['qiandan_money'])) {
- credits($request->employee->root_id, $param['qiandan_money'], 'qiandan_money_integral', 0); //贡献值
- }
- if (isset($param['measuring_integral'])) {
- credits($request->employee->root_id, $param['measuring_integral'], 'measuring_integral_integral', 0); //贡献值
- }
- if (isset($param['measuring_suite_integral'])) {
- credits($request->employee->root_id, $param['measuring_suite_integral'], 'measuring_suite_integral_integral', 0); //贡献值
- }
- if (isset($param['measuring_villa_integral'])) {
- credits($request->employee->root_id, $param['measuring_villa_integral'], 'measuring_villa_integral_integral', 0); //贡献值
- }
- if (isset($param['hxtime'])) {
- credits($request->employee->root_id, $param['hxtime'], 'agent_hx_time', 0); //交定核销时间
- }
- if (isset($param['wanghong'])) {
- credits($request->employee->root_id, $param['wanghong'], 'wanghong_integral', 0); //贡献值
- }
- if (isset($param['jifen']) && isset($param['money'])) {
- $json = json_encode(['jifen' => $param['jifen'], 'money' => $param['money']]);
- credits($request->employee->root_id, $json, 'reduce_integral', 0); //贡献值
- }
- if (isset($param['wjifen']) && isset($param['wmoney'])) {
- $json = json_encode(['jifen' => $param['wjifen'], 'money' => $param['wmoney']]);
- credits($request->employee->root_id, $json, 'wang_reduce_integral', 0); //贡献值
- }
- if (isset($param['ptagentshare'])) {
- credits($request->employee->root_id, $param['ptagentshare'], 'ptagentshare_integral', 0); //积分
- }
- if (isset($param['whagentshare'])) {
- credits($request->employee->root_id, $param['whagentshare'], 'whagentshare_integral', 0); //积分
- }
- if (isset($param['putong'])) {
- credits($request->employee->root_id, $param['putong'], 'putong_integral', 0); //积分
- }
- if (isset($param['hxtime_sign'])) {
- credits($request->employee->root_id, $param['hxtime_sign'], 'agent_hxtime_sign', 0); //签单核销时间
- }
- if (isset($param['produceclue'])) {
- credits($request->employee->root_id, $param['produceclue'], 'produceclue_integral', 0); //签单核销时间
- }
- return json(['code' => 0, 'msg' => '保存成功']);
- }
- /**
- * 网红经纪人 - 积分设置
- */
- public function red_integral_setting()
- {
- return View::fetch();
- }
- /**
- * 设置管理
- */
- public function set()
- {
- $request = request();
- if (!request()->isAjax()) {
- $setdata = Setting::where([['root_id', '=', $request->employee->root_id], ['name', 'in', ['agentInviteShow', 'agentBackgroundImg', 'agentSettingName', 'agentEmployeeAdd']]])->column('content', 'name');
- if (empty($setdata)) {
- View::assign('img', '');
- View::assign('imgs', '');
- View::assign('name', '');
- View::assign('set_switch', true);
- } else {
- $oss_url = config('app.ali_oss_bindurl');
- $url = !empty($setdata['agentInviteShow']) ? 'https://' . $oss_url . '/' . $setdata['agentInviteShow'] : '';
- $urls = !empty($setdata['agentBackgroundImg']) ? 'https://' . $oss_url . '/' . $setdata['agentBackgroundImg'] : '';
- View::assign('img', $url);
- View::assign('imgs', $urls);
- View::assign('name', !empty($setdata['agentSettingName']) ? $setdata['agentSettingName'] : '');
- View::assign('set_switch', isset($setdata['agentEmployeeAdd']) ? $setdata['agentEmployeeAdd'] : true);
- }
- return View::fetch();
- }
- $data = Request::param(['img', 'imgs', 'name', 'defaults', 'set_switch']);
- if (!empty($data['img'])) $this->setsave($request->employee->root_id, $data['img'], 'agentInviteShow');
- if (!empty($data['imgs'])) $this->setsave($request->employee->root_id, $data['imgs'], 'agentBackgroundImg');
- if (!empty($data['name'])) $this->setsave($request->employee->root_id, $data['name'], 'agentSettingName');
- if (!empty($data['defaults'])) $this->setsave($request->employee->root_id, null, 'agentBackgroundImg');
- $this->setsave($request->employee->root_id, !isset($data['set_switch']) ? 'false' : 'true', 'agentEmployeeAdd');
- return json(['code' => 0, 'msg' => '操作成功']);
- }
- /**
- * 设置表添加方法
- */
- public function setsave($root_id, $val, $name)
- {
- $where[] = ['name', '=', $name];
- $where[] = ['root_id', '=', $root_id];
- $info = Setting::where($where)->find();
- if ($info) {
- Setting::where($where)->update(['content' => $val]);
- } else {
- $save['name'] = $name;
- $save['root_id'] = $root_id;
- $save['content'] = $val;
- $save['state'] = 1;
- Setting::insert($save);
- }
- }
- /**
- * 设置经纪人主题名称
- */
- public function set_name()
- {
- $request = request();
- if (!request()->isAjax()) {
- $name = Setting::where(['root_id' => $request->employee->root_id, 'name' => 'agentSettingName'])->value('content');
- View::assign('name', $name);
- return View::fetch();
- }
- $name = Request::param('name');
- if (empty($name)) return json(['code' => 1, 'msg' => '请输入名称']);
- $set = Setting::where(['root_id' => $request->employee->root_id, 'name' => 'agentSettingName'])->find();
- if (!empty($set)) {
- $set->content = $name;
- $set->save();
- } else {
- Setting::create([
- 'root_id' => $request->employee->root_id,
- 'name' => 'agentSettingName',
- 'content' => $name,
- 'state' => 1
- ]);
- }
- return json(['code' => 0, 'msg' => '操作成功']);
- }
- /**
- * 添加经纪人类别
- */
- public function add_agenttype()
- {
- $request = request();
- $param = $request->only(['name']);
- $add = [
- 'type_name' => $param['name'],
- 'root_id' => $request->employee->root_id
- ];
- $ms = AgentType::insertGetId($add);
- if ($ms) {
- return json(['code' => 0, 'msg' => '添加成功']);
- } else {
- return json(['code' => 1, 'msg' => '添加失败']);
- }
- }
- /**
- * 修改经纪人类别
- */
- public function edit_agenttype()
- {
- $request = request();
- $param = $request->only(['id', 'name']);
- $data = AgentType::where([['root_id', '=', $request->employee->root_id], ['id', '=', $param['id']]])->find();
- if (empty($data)) return json(['code' => 1, 'msg' => '数据不存在']);
- $data->type_name = $param['name'];
- $ms = $data->save();
- if ($ms) {
- return json(['code' => 0, 'msg' => '修改成功']);
- } else {
- return json(['code' => 1, 'msg' => '修改失败']);
- }
- }
- /**
- * 删除经纪人类别
- */
- public function del_agenttype()
- {
- $request = request();
- $param = $request->only(['id']);
- $data = AgentType::where([['root_id', '=', $request->employee->root_id], ['id', '=', $param['id']]])->find();
- if (empty($data)) return json(['code' => 1, 'msg' => '数据不存在']);
- $check = AgentUser::where([['root_id', '=', $request->employee->root_id], ['type', '=', $data['id']]])->count();
- if (!empty($check)) return json(['code' => 1, 'msg' => '当前类别下有经纪人,不能删除']);
- //判断最后一个不能删除
- $last = AgentType::where([['root_id', '=', $request->employee->root_id], ['status', '=', 1]])->count();
- if ($last == 1) return json(['code' => 1, 'msg' => '最后一个类别,不能删除']);
- $ms = $data->delete();
- if ($ms) {
- return json(['code' => 0, 'msg' => '删除成功']);
- } else {
- return json(['code' => 1, 'msg' => '删除失败']);
- }
- }
- /**
- * 获取当前类别
- */
- public function get_agentrule()
- {
- $request = request();
- $param = $request->only(['id']);
- $data = AgentType::where([['root_id', '=', $request->employee->root_id], ['id', '=', $param['id']]])->find();
- if (empty($data)) return json(['code' => 1, 'msg' => '数据不存在']);
- $data['count'] = json_decode($data['count']);
- return json(['code' => 0, 'data' => $data, 'msg' => '获取成功']);
- }
- /**
- * 设置类别的规则
- */
- public function set_agentrule()
- {
- $request = request();
- $param = Request::only(['id', 'daodian' => '', 'jiaoding' => '', 'qiandan' => '', 'putong' => '', 'hxtime' => '', 'hxtime_sign' => '', 'ptagentshare' => '', 'produceclue' => '', 'measuring' => '', 'measuring_suite' => '', 'measuring_villa' => '', 'qiandan_scale' => '', 'qiandan_money' => '']);
- $content = [
- 'daodian_integral' => $param['daodian'],
- 'measuring_integral' => $param['measuring'],
- 'measuring_suite_integral' => $param['measuring_suite'],
- 'measuring_villa_integral' => $param['measuring_villa'],
- 'jiaoding_integral' => $param['jiaoding'],
- 'qiandan_integral' => $param['qiandan'],
- 'qiandan_scale_integral' => $param['qiandan_scale'],
- 'qiandan_money_integral' => $param['qiandan_money'],
- 'ptagentshare_integral' => $param['ptagentshare'],
- 'putong_integral' => $param['putong'],
- 'agent_hxtime_sign' => $param['hxtime_sign'],
- 'agent_hx_time' => $param['hxtime'],
- 'produceclue_integral' => $param['produceclue']
- ];
- $data = AgentType::where([['root_id', '=', $request->employee->root_id], ['id', '=', $param['id']]])->find();
- if (empty($data)) return json(['code' => 1, 'msg' => '数据不存在']);
- $data->count = json_encode($content);
- $ms = $data->save();
- return json(['code' => 0, 'msg' => '设置成功']);
- }
- /**
- * 设置奖品
- */
- public function prize_setting()
- {
- $request = request();
- $root_id = $request->employee->root_id;
- if (!request()->isAjax()) {
- $list = AgentPrize::where([['root_id', '=', $root_id], ['status', '=', 1]])->select()->toArray();
- View::assign('list', $list);
- $where[] = ['code', '=', 'reduce_integral'];
- $where[] = ['root_id', '=', $request->employee->root_id];
- $person2 = CreditsSetting::where($where)->value('value');
- $data['reduce_integral'] = $person2 ? json_decode($person2, true) : ['jifen' => 1, 'money' => 0];
- View::assign('data', $data);
- return View::fetch();
- }
- }
- /**
- * 添加奖品
- */
- public function add_prize()
- {
- $request = request();
- $param = $request->only(['name', 'integral', 'img' => '']);
- if (!request()->isAjax()) {
- return View::fetch();
- }
- $add = [
- 'good_name' => $param['name'],
- 'root_id' => $request->employee->root_id,
- 'integral' => $param['integral'],
- 'img' => $param['img']
- ];
- $ms = AgentPrize::insertGetId($add);
- if ($ms) {
- return json(['code' => 0, 'msg' => '添加成功']);
- } else {
- return json(['code' => 1, 'msg' => '添加失败']);
- }
- }
- /**
- * 修改奖品
- */
- public function edit_prize()
- {
- $request = request();
- $param = $request->only(['id', 'name', 'integral', 'img' => '']);
- $data = AgentPrize::where([['root_id', '=', $request->employee->root_id], ['id', '=', $param['id']]])->find();
- if (empty($data)) return json(['code' => 1, 'msg' => '数据不存在']);
- if (!request()->isAjax()) {
- View::assign('data', $data);
- return View::fetch();
- }
- $data->good_name = $param['name'];
- if (!empty($param['img'])) $data->img = $param['img'];
- $data->integral = $param['integral'];
- $data->save();
- return json(['code' => 0, 'msg' => '修改成功']);
- }
- /**
- * 删除奖品
- */
- public function del_prize()
- {
- $request = request();
- $param = $request->only(['id']);
- $data = AgentPrize::where([['root_id', '=', $request->employee->root_id], ['id', '=', $param['id']]])->find();
- if (empty($data)) return json(['code' => 1, 'msg' => '数据不存在']);
- $ms = $data->delete();
- if ($ms) {
- return json(['code' => 0, 'msg' => '删除成功']);
- } else {
- return json(['code' => 1, 'msg' => '删除失败']);
- }
- }
- /**
- * 经纪人内容管理
- */
- public function agent_article_list()
- {
- $request = request();
- $param = $request->only(['id', 'title', 'employee_id', 'from' => 2, 'add_time', 'page' => 1, 'limit' => 10]);
- if (!request()->isAjax()) {
- $employee = Employee::where([['root_id', '=', $request->employee->root_id], ['state', '=', '在职']])->column('id,name');
- View::assign('employee', $employee);
- return View::fetch();
- }
- //var_dump($param['from']);exit;
- $where[] = ['root_id', '=', $request->employee->root_id];
- $where[] = ['from', '=', $param['from']];
- if (!empty($param['title'])) $where[] = ['title', 'like', '%' . $param['title'] . '%'];
- if (!empty($param['employee_id'])) $where[] = ['employee_id', '=', $param['employee_id']];
- if (!empty($param['add_time'])) {
- $time = explode(' - ', $param['add_time']);
- $where[] = ['addtime', 'between', [$time[0], $time[1]]];
- }
- $list = AgentArticle::with(['employee' => function ($query) {
- $query->field('id,name,opt_name');
- }])->where($where)->order('addtime desc')->page($param['page'], $param['limit'])->select()->toArray();
- $vrObj = new Vr();
- foreach ($list as $key => $val) {
- if ($val['type'] == 1) $list[$key]['file_img'] = $val['cover'];
- if ($val['type'] == 2) $list[$key]['file_img'] = !empty($val['file'][0]) ? $val['file'][0] : '';
- 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])) : '';
- if ($val['type'] == 4) {
- $group = VrGroup::where('id', $val['vr_group_ids'])->field('pic_path')->findOrEmpty();
- $list[$key]['file_img'] = $group->isEmpty() ? '' : $group->pic_path;
- }
- }
- $count = AgentArticle::where($where)->count();
- return json(['code' => 0, 'msg' => '获取成功', 'data' => $list, 'count' => $count]);
- }
- /**
- * 单独查询数据
- */
- public function sel_artdata($list, $emplist, $root_id)
- {
- foreach ($list as &$item) {
- $item['employee'] = !empty($emplist[$item['employee_id']]) ? $emplist[$item['employee_id']] : '';
- switch ($item['type']) {
- case 'Article':
- $find = Article::where([
- ['root_id', '=', $root_id],
- ['delete_time', '=', 0],
- ['publish', '=', 1],
- ['id', '=', $item['data_id']]
- ])->field('id,title,cover_img')->find();
- $item['content_id'] = !empty($find['id']) ? $find['id'] : 0;
- $item['title'] = !empty($find['title']) ? $find['title'] : '';
- $item['file_img'] = !empty($find['cover_img']) ? $find['cover_img'] : '';
- break;
- case 'MaterialCase':
- $find = MaterialCase::where([
- ['root_id', '=', $root_id],
- ['del', '=', 0],
- ['publish', '=', 1],
- ['id', '=', $item['data_id']]
- ])->field('id,title,cover_img')->find();
- $item['content_id'] = !empty($find['id']) ? $find['id'] : 0;
- $item['title'] = !empty($find['title']) ? $find['title'] : '';
- $item['file_img'] = !empty($find['cover_img']) ? $find['cover_img'] : '';
- break;
- case 'Video':
- $find = Video::where([
- ['root_id', '=', $root_id],
- ['delete_time', '=', 0],
- ['publish', '=', 1],
- ['id', '=', $item['data_id']]
- ])->field('id,title,video_url')->find();
- $item['content_id'] = !empty($find['id']) ? $find['id'] : 0;
- $item['title'] = !empty($find['title']) ? $find['title'] : '';
- $item['file_img'] = !empty($find['video_url']) ? $find['video_url'] : '';
- $item['file_type'] = 1;
- break;
- case 'CompanyStrength':
- $find = CompanyStrength::where([
- ['root_id', '=', $root_id],
- ['del', '=', 0],
- ['publish', '=', 1],
- ['id', '=', $item['data_id']]
- ])->field('id,title,pics,difference')->find();
- $item['content_id'] = !empty($find['id']) ? $find['id'] : 0;
- $item['title'] = !empty($find['title']) ? $find['title'] : '';
- $item['file_img'] = !empty($find['pics']) ? $find['pics'] : '';
- $item['difference'] = !empty($find['difference']) ? $find['difference'] : '';
- break;
- case 'MaterialEvidence':
- $find = MaterialEvidence::where([
- ['root_id', '=', $root_id],
- ['del', '=', 0],
- ['publish', '=', 1],
- ['id', '=', $item['data_id']]
- ])->field('id,title,pics,difference')->find();
- $item['content_id'] = !empty($find['id']) ? $find['id'] : 0;
- $item['title'] = !empty($find['title']) ? $find['title'] : '';
- $item['file_img'] = !empty($find['pics'][0]) ? $find['pics'][0] : '';
- $item['difference'] = !empty($find['difference']) ? $find['difference'] : '';
- break;
- case 'Building':
- $find = Building::where([
- ['root_id', '=', $root_id],
- ['del', '=', 0],
- ['id', '=', $item['data_id']]
- ])->field('id,community_id,name,cover')->find();
- $item['content_id'] = !empty($find['id']) ? $find['id'] : 0;
- $item['title'] = !empty($find['name']) ? $find['name'] : '';
- $item['file_img'] = !empty($find['cover'][0]) ? $find['cover'][0] : '';
- break;
- case 'AgentArticle':
- $find = AgentArticle::where([
- ['root_id', '=', $root_id],
- ['id', '=', $item['data_id']]
- ])->field('id,title,file,type')->find();
- $item['content_id'] = !empty($find['id']) ? $find['id'] : 0;
- $item['title'] = !empty($find['title']) ? $find['title'] : '';
- $file = !empty($find['file'][0]) ? $find['file'][0] : '';
- $item['file_img'] = !empty($find['file'][0]) ? $find['file'][0] : '';
- $item['file_type'] = !empty($find['type']) ? $find['type'] : 0;
- break;
- default:
- $item['content_id'] = 0;
- $item['title'] = '';
- $item['file_img'] = '';
- break;
- }
- }
- return $list;
- }
- /**
- * 员工分享列表
- */
- public function agtemp_artlist()
- {
- $request = request();
- $root_id = $request->employee->root_id;
- $param = $request->only(['id', 'title', 'employee_id', 'add_time', 'page' => 1, 'limit' => 10]);
- $where[] = ['root_id', '=', $root_id];
- if (!empty($param['employee_id'])) $where[] = ['employee_id', '=', $param['employee_id']];
- if (!empty($param['add_time'])) {
- $time = explode(' - ', $param['add_time']);
- $where[] = ['addtime', 'between', [$time[0], $time[1]]];
- }
- if (!empty($param['title'])) {
- $list = AgentShareContent::where($where)->column('id,type,employee_id,data_id');
- $emplist = [];
- $titlist = $this->sel_artdata($list, $emplist, $root_id);
- foreach ($titlist as $v) {
- if (strpos(trim($v['title']), $param['title']) !== false) $selid[] = $v['id'];
- }
- $where[] = ['id', 'in', $selid];
- }
- $list = AgentShareContent::where($where)->page($param['page'], $param['limit'])->order('addtime desc')->select()->toArray();
- $emplist = Employee::where([['root_id', '=', $root_id], ['id', 'in', array_column($list, 'employee_id')]])->column('name,opt_name', 'id');
- $list = $this->sel_artdata($list, $emplist, $root_id);
- $count = AgentShareContent::where($where)->count();
- return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']);
- }
- /**
- * 添加内容
- */
- public function add_article()
- {
- $request = request();
- $param = $request->only(['title', 'type', 'covers' => '', 'desc', 'video_url' => '', 'vrurl' => '', 'cover' => '', 'vr_group_ids' => '']);
- if (!request()->isAjax()) {
- return View::fetch();
- }
- $file = '';
- if ($param['type'] == 1) $file = $param['video_url'];
- if ($param['type'] == 2) $file = $param['covers'];
- if ($param['type'] == 3) $file = $param['vrurl'];
- $add = [
- 'title' => $param['title'],
- 'type' => $param['type'],
- 'cover' => $param['cover'],
- 'file' => $file,
- 'content' => $param['desc'],
- 'employee_id' => $request->employee->id,
- 'root_id' => $request->employee->root_id,
- 'from' => 2,
- 'addtime' => time(),
- 'vr_group_ids' => $param['vr_group_ids']
- ];
- $ms = AgentArticle::create($add);
- AgentShareContent::create(['root_id' => $request->employee->root_id, 'employee_id' => $request->employee->id, 'data_id' => $ms->id, 'type' => 'AgentArticle','from'=>2]);
- if ($ms) {
- return json(['code' => 0, 'msg' => '添加成功']);
- } else {
- return json(['code' => 1, 'msg' => '添加失败']);
- }
- }
- /**
- * 开启文章
- */
- public function apipublish()
- {
- $request = request();
- $param = $request->only(['id']);
- $data = AgentArticle::where([['root_id', '=', $request->employee->root_id], ['id', '=', $param['id']]])->find();
- if (empty($data)) return json(['code' => '1', 'msg' => '数据不存在']);
- $data->disable = $data->disable == 0 ? 1 : 0;
- $ms = $data->save();
- if ($ms) {
- return json(['code' => 0, 'msg' => '修改成功']);
- } else {
- return json(['code' => 1, 'msg' => '修改失败']);
- }
- }
- /*
- * 富文本图片
- */
- public function imgUpload()
- {
- $bindUrl = config('app.ali_oss_bindurl');
- $data = [
- 'src' => 'https://' . $bindUrl . '/' . Request::param('file'),
- 'title' => ''
- ];
- return json(['code' => 0, 'msg' => '', 'data' => $data]);
- }
- /**
- * 编辑文章
- */
- public function edit_article()
- {
- $request = request();
- $param = $request->only(['id', 'title', 'type', 'covers' => '', 'desc', 'video_url' => '', 'vrurl' => '', 'cover' => '', 'oldcovers' => '', 'vr_group_ids' => '']);
- $data = AgentArticle::where([['root_id', '=', $request->employee->root_id], ['id', '=', $param['id']]])->find();
- if (empty($data)) return json(['code' => 1, 'msg' => '数据不存在']);
- if (!request()->isAjax()) {
- if (!empty($data)) {
- $data['fileuri'] = $data['covers'] = $data['vrurl'] = '';
- if ($data['type'] == 1) $data['fileuri'] = !empty($data['file']) ? $data['file'][0] : '';
- if ($data['type'] == 2) $data['covers'] = !empty($data['file']) ? $data['file'] : [];
- if ($data['type'] == 3) $data['vrurl'] = !empty($data['file']) ? str_replace('https://' . config('app.ali_oss_bindurl') . '/', '', $data['file'][0]) : '';
- $data['oldfile'] = $data->getData('file');
- $data['group_name'] = $data['vr_group_ids'] ? (VrGroup::where('id', $data['vr_group_ids'])->value('title') ?: '未命名作品') : '未命名作品';
- }
- View::assign('data', $data);
- return View::fetch();
- }
- if (!empty($param['oldcovers'])) {
- $param['covers'] = trim(implode(',', $param['oldcovers']) . ',' . $param['covers'], ',');
- }
- //var_dump($param);exit;
- $file = '';
- if ($param['type'] == 1) $file = $param['video_url'];
- if ($param['type'] == 2) $file = $param['covers'];
- if ($param['type'] == 3) $file = $param['vrurl'];
- //$data->cover = !empty($param['cover']) ? $param['cover'] : $param['oldcover'];
- $data->cover = $param['cover'];
- $data->title = $param['title'];
- $data->type = $param['type'];
- $data->file = $file;
- $data->content = $param['desc'];
- $data->vr_group_ids = $param['vr_group_ids'];
- $ms = $data->save();
- if ($ms) {
- return json(['code' => 0, 'msg' => '修改成功']);
- } else {
- return json(['code' => 1, 'msg' => '修改失败']);
- }
- }
- /**
- * 删除文章
- */
- public function del_article()
- {
- $request = request();
- $param = $request->only(['id', 'title', 'type', 'covers' => '', 'desc', 'fileuri' => '', 'vrurl' => '']);
- $data = AgentArticle::where([['root_id', '=', $request->employee->root_id], ['id', '=', $param['id']]])->find();
- if (empty($data)) return json(['code' => 1, 'msg' => '数据不存在']);
- $ms = $data->delete();
- if ($ms) {
- return json(['code' => 0, 'msg' => '删除成功']);
- } else {
- return json(['code' => 1, 'msg' => '删除失败']);
- }
- }
- }
|