123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990 |
- <?php
- namespace app\adminall\controller;
- use app\BaseController;
- use app\model\ConstructionStep;
- use app\model\WeworksingleCompanySetting;
- use think\facade\View;
- use think\facade\Request;
- use app\model\Company as ModelCompany;
- use app\model\CompanyBrand;
- use app\model\Employee;
- use app\model\Miniprogram;
- use app\model\Org;
- use Exception;
- use think\facade\Db;
- use wx\miniprogram\Qrcode;
- use app\model\OperateLog;
- use app\model\TrainClassCate;
- use app\model\TalkskillUsersCate;
- use app\model\CompanyStrengthCate;
- use app\model\TalkskillCates;
- use app\model\Company as CompanyModel;
- use app\model\Wechat;
- class Company extends BaseController
- {
- /**
- * 列表
- */
- public function index()
- {
- if (!Request::isAjax()) {
- return View::fetch();
- }
- $param = Request::only(['page', 'limit', 'keyword']);
- $where = [];
- if (!empty($param['keyword'])) {
- $where[] = ['company_name', 'like', '%' . $param['keyword'] . '%'];
- }
- $list = ModelCompany::where($where)->page($param['page'], $param['limit'])->order('addtime desc')->select()->toArray();
- $column = array_column($list, 'root_id');
- $mini = Miniprogram::where('root_id', 'in', $column)->column('company', 'root_id');
- foreach ($list as &$m) {
- $m['bind_mini'] = isset($mini[$m['root_id']]) ? 1 : 0;
- }
- $count = ModelCompany::where($where)->count();
- return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']);
- }
- /**
- * 添加视图
- */
- public function add()
- {
- return View::fetch();
- }
- /**
- * 修改视图
- */
- public function edit($id)
- {
- $company = ModelCompany::where('id', $id)->find();
- $company['phone'] = Employee::where([['top_one', '=', 1], ['root_id', '=', $company->root_id]])->value('phone');
- View::assign('data', $company);
- return View::fetch();
- }
- /**
- * 添加企业
- */
- public function addSave()
- {
- $param = request()->param();
- $org_id = Org::insertGetId([
- 'name' => $param['company_name'],
- 'pid' => 0,
- 'level' => 0,
- 'info' => $param['company_name'],
- 'status' => 1
- ]);
- Db::startTrans();
- try {
- Org::where('id', $org_id)->save(['path' => $org_id . '-']);
- ModelCompany::create([
- 'company_name' => $param['company_name'],
- 'start_date' => date('Y-m-d'),
- 'end_date' => $param['end_date'],
- 'logo' => $param['logo'] ?? '',
- 'root_id' => $org_id,
- 'tel' => $param['tel'],
- 'mini' => $param['mini'],
- 'shop_number' => $param['shop_number'] ?? 0
- ]);
- $msg = $this->miniInit($org_id, str_rand(6));
- if ($msg) return json(['code' => 1, 'msg' => $msg]);
- Employee::create([
- 'phone' => $param['phone'],
- 'opt_name' => $param['company_name'],
- 'root_id' => $org_id,
- 'org_id' => $org_id,
- 'grant_id' => 2,
- 'is_manager' => 1,
- 'verified' => 1,
- 'state' => '在职',
- 'top_one' => 1
- ]);
- } catch (Exception $e) {
- // 回滚事务
- Db::rollback();
- return json(['code' => 1, 'msg' => $e->getMessage()]);
- }
- Db::commit();
- return json(['code' => 0, 'msg' => '添加成功']);
- }
- /**
- * 修改企业
- */
- public function editSave()
- {
- $param = request()->only(['phone', 'company_name', 'end_date', 'id', 'root_id', 'logo', 'tel', 'mini']);
- $msg = $this->setInfo($param['id'], $param['company_name'], 'company_name');
- $employee = Employee::where([['top_one', '=', 1], ['root_id', '=', $param['root_id']]])->find();
- if ($param['phone'] != $employee['phone']) {
- $employee->phone = $param['phone'];
- $employee->save();
- }
- unset($param['phone']);
- $company = ModelCompany::where('id', $param['id'])->find();
- $old = $company->mini;
- $company->save($param);
- if ($param['mini'] != $old) $this->miniInit($company->root_id);
- return json(['code' => 0, 'msg' => '修改成功']);
- }
- /**
- * 取消用户授权
- */
- public function auth()
- {
- $id = input('post.id/d');
- $company = ModelCompany::where('id', $id)->find();
- $company->status = $company->status == 1 ? 0 : 1;
- $company->save();
- return json(['code' => 0, 'msg' => '更新成功']);
- }
- /**
- * 更新到期有效时间
- */
- public function endDate()
- {
- $id = input('post.id/d');
- $date = input('post.value');
- ModelCompany::where('id', $id)->update(['end_date' => $date]);
- return json(['code' => 0, 'msg' => '更新成功']);
- }
- /**
- * 修改名称
- */
- public function setInfo($id, $set_value, $field)
- {
- $rs = ModelCompany::where('id', $id)->find();
- if (!$rs) return json(['code' => 1, 'msg' => '修改失败']);
- //修改名称
- if ($field == 'company_name') {
- //修改org里的分组名称
- $path = Org::where('id', $rs['root_id'])->find();
- $aimedones = Org::where([['path', 'like', $path['path'] . '%']])->select();
- foreach ($aimedones as $item) {
- $rightinfo = str_replace($rs->company_name, $set_value, $item->info);
- Org::where(['id' => $item['id']])->update(['info' => $rightinfo]);
- }
- $path->name = $set_value;
- $path->save();
- //修改企业名称
- $rs->company_name = $set_value;
- $rs->save();
- //修改miniprogram表名称
- Miniprogram::where('root_id', $rs['root_id'])->update(['company' => $set_value]);
- }
- //修改店面数量
- if ($field == 'shop_number') {
- $join = ModelCompany::where('company_group', $rs['id'])->count();
- if ($set_value < $join) return json(['code' => 1, 'msg' => '修改失败,当前已存在'.$join.'家店面']);
-
- $rs->shop_number = $set_value;
- $rs->save();
- }
- return json(['code' => 0, 'msg' => '修改成功']);
- }
- /*
- * 企业授权信息修改
- */
- public function setting($root_id)
- {
- if (!Request::isAjax()) {
- $mini = Miniprogram::where('root_id', $root_id)->find();
- View::assign('mini', $mini);
- View::assign('root_id', $root_id);
- $notify = empty($mini['notify']) ? str_rand(6) : $mini['notify'];
- View::assign('notify', $notify);
- $url = url('api/miniEventPush/' . $notify, [], true, true)->build();
- View::assign('url', $url);
- return View::fetch();
- }
- $param = request()->param();
- $msg = $this->miniprogram($param);
- return $msg;
- }
- /**
- * 小程序绑定
- */
- private function miniprogram($param)
- {
- $program = Miniprogram::where([['root_id', '=', $param['root_id']]])->findOrEmpty();
- if (!empty($param['appid']) && !empty($param['secret'])) {
- $accessToken = getAccessToken($param['appid'], $param['secret']);
- if (empty($accessToken)) return json(['code' => 1, 'msg' => '配置失败,appid,secret不正确或小程序业务域名未配置']);
- // 邀请二维码生成
- $miniQr = new Qrcode();
- // 1)管理员二维码
- $qr = $miniQr->getUnlimited($accessToken, [
- 'scene' => 'manager=' . $param['root_id'],
- 'page' => 'mycustomer/pages/invite/invite',
- 'width' => '280px',
- 'check_path' => false
- ]);
- $rs = json_decode($qr, true);
- if (!is_null($rs)) {
- trace($rs, 'error');
- return json(['code' => 1, 'msg' => '配置失败,appid,secret不正确或小程序业务域名未配置']);
- }
- $managerQr = 'invite' . DIRECTORY_SEPARATOR . uniqid() . '.jpeg';
- ossContentUpload($managerQr, $qr);
- // 2)员工二维码
- $qr = $miniQr->getUnlimited($accessToken, [
- 'scene' => 'employee=' . $param['root_id'],
- 'page' => 'mycustomer/pages/invite/invite',
- 'width' => '280px',
- 'check_path' => false
- ]);
- $rs = json_decode($qr, true);
- if (!is_null($rs)) {
- return json(['code' => 1, 'msg' => '配置失败,appid,secret不正确或小程序业务域名未配置']);
- }
- $employeeQr = 'invite' . DIRECTORY_SEPARATOR . uniqid() . '.jpeg';
- ossContentUpload($employeeQr, $qr);
- } else { // 公开版志远装饰
- $accessToken = '';
- // 二维码生成到企业小程序设置中
- $defaultAccesstoken = Miniprogram::where([['notify', '=', config('app.cgi')]])->find()->accesstoken;
- $miniQr = new Qrcode();
- // 1)管理员二维码
- $qr = $miniQr->getUnlimited($defaultAccesstoken, [
- 'scene' => 'cgi=' . $param['notify'] . '&manager=' . $param['root_id'],
- 'page' => 'mycustomer/pages/invite/invite',
- 'width' => '280px',
- 'check_path' => false
- ]);
- $rs = json_decode($qr, true);
- if (!is_null($rs)) {
- trace($rs, 'error');
- return json(['code' => 1, 'msg' => '配置失败,appid,secret不正确或小程序业务域名未配置']);
- }
- $managerQr = 'invite' . DIRECTORY_SEPARATOR . uniqid() . '.jpeg';
- ossContentUpload($managerQr, $qr);
- // 2)员工二维码
- $qr = $miniQr->getUnlimited($defaultAccesstoken, [
- 'scene' => 'cgi=' . $param['notify'] . '&employee=' . $param['root_id'],
- 'page' => 'mycustomer/pages/invite/invite',
- 'width' => '280px',
- 'check_path' => false
- ]);
- $rs = json_decode($qr, true);
- if (!is_null($rs)) {
- return json(['code' => 1, 'msg' => '配置失败,appid,secret不正确或小程序业务域名未配置']);
- }
- $employeeQr = 'invite' . DIRECTORY_SEPARATOR . uniqid() . '.jpeg';
- ossContentUpload($employeeQr, $qr);
- }
- $company_name = ModelCompany::where('root_id', $param['root_id'])->value('company_name');
- $data = [
- 'appid' => $param['appid'],
- 'secret' => $param['secret'],
- 'account' => $param['account'],
- 'encodingAesKey' => $param['encodingAesKey'],
- 'token' => $param['token'],
- 'manager_qr' => $managerQr,
- 'employee_qr' => $employeeQr,
- 'accesstoken' => $accessToken,
- 'expire' => time() + 7100,
- 'root_id' => $param['root_id'],
- 'notify' => $param['notify'],
- 'company' => $company_name
- ];
- $program->save($data);
- return json(['code' => 0, 'msg' => '保存成功']);
- }
- /**
- * 初始化小程序配置
- */
- private function miniInit($rootId, $notify = null)
- {
- $program = Miniprogram::where([['root_id', '=', $rootId]])->findOrEmpty();
- if ($program->isEmpty()) {
- if (empty($notify)) return '缺少参数notify';
- $data = [
- 'appid' => '',
- 'secret' => '',
- 'account' => '',
- 'encodingAesKey' => '',
- 'token' => '',
- 'manager_qr' => '',
- 'employee_qr' => '',
- 'accesstoken' => '',
- 'expire' => 0,
- 'root_id' => $rootId,
- 'company' => '',
- 'notify' => $notify
- ];
- $program->save($data);
- }
- $notify = $program->notify;
- // 二维码生成到企业小程序设置中
- $defaultAccesstoken = $program->accesstoken;
- if (empty($defaultAccesstoken)) return '默认accesstoken获取失败';
- $miniQr = new Qrcode();
- // 1)管理员二维码
- $qr = $miniQr->getUnlimited($defaultAccesstoken, [
- 'scene' => 'cgi=' . $notify . '&manager=' . $rootId,
- 'page' => 'mycustomer/pages/invite/invite',
- 'width' => '280px',
- 'check_path' => false
- ]);
- $rs = json_decode($qr, true);
- if (!is_null($rs)) {
- trace($rs, 'error');
- return '管理员二维码生成失败';
- }
- $managerQr = 'invite' . DIRECTORY_SEPARATOR . uniqid() . '.jpeg';
- ossContentUpload($managerQr, $qr);
- // 2)员工二维码
- $qr = $miniQr->getUnlimited($defaultAccesstoken, [
- 'scene' => 'cgi=' . $notify . '&employee=' . $rootId,
- 'page' => 'mycustomer/pages/invite/invite',
- 'width' => '280px',
- 'check_path' => false
- ]);
- $rs = json_decode($qr, true);
- if (!is_null($rs)) return '员工二维码生成失败';
- $employeeQr = 'invite' . DIRECTORY_SEPARATOR . uniqid() . '.jpeg';
- ossContentUpload($employeeQr, $qr);
- $company_name = ModelCompany::where('root_id', $rootId)->value('company_name');
- $data = [
- 'manager_qr' => $managerQr,
- 'employee_qr' => $employeeQr,
- 'company' => $company_name
- ];
- $program->save($data);
- }
- /**
- * 集团列表
- */
- public function group()
- {
- /** 页面请求 */
- if (!$this->request->isAjax()) {
- $miniprogram = Wechat::field('id, type')->select();
- View::assign('miniprogram', $miniprogram);
- return View::fetch();
- }
- /** ajax请求获取数据 */
- // 请求参数获取
- $param = $this->request->only(['page', 'limit', 'keyword']);
- // 只取集团企业信息
- $where = [['company_group', '=', 0]];
- // 查询条件
- if (!empty($param['keyword'])) {
- $where[] = ['company_name', 'like', '%' . $param['keyword'] . '%'];
- }
- // 列表获取
- $list = ModelCompany::with(['mini' => function ($query) {
- $query->bind(['type']);
- }])->field('id,company_name,start_date,end_date,status,tel,addtime,root_id,company_group,mini,shop_number')->where($where)->page($param['page'], $param['limit'])->order('addtime desc')->select();
- // 列表总数获取
- $count = ModelCompany::where($where)->count();
- // 查询结果返回
- return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']);
- }
- /**
- * 登录日志
- */
- public function loginlog()
- {
- $id = input('id', 0);
- $page = input('page', 1);
- $limit = input('limit', 10);
- if (!Request::isAjax()) {
- //店面
- $shops = ModelCompany::where([['company_group', '=', $id]])->field('id,company_name')->select()->toArray();
- $data['group'] = $shops;
- // 人员
- view::assign('data', $data);
- view::assign('id', $id);
- return View::fetch();
- }
- $group = input('group', 0);
- $cw[] = ['company_group', '=', $id];
- if ($group) {
- $cw[] = ['id', '=', $group];
- }
- //所有店面
- $shops = ModelCompany::where($cw)->column('root_id');
- // var_dump($shops);die;
- $w[] = ['root_id', 'in', $shops];
- // $w = [];
- $list = OperateLog::with(['employee', 'company'])->where($w)->page($page, $limit)->order('id desc')->select()->toArray();
- if ($list) {
- foreach ($list as $k => $v) {
- $list[$k]['company_name'] = isset($v['company']) && $v['company'] ? $v['company']['company_name'] : '';
- $list[$k]['company_group'] = isset($v['company']) && $v['company'] ? $v['company']['company_group'] : 0;
- $list[$k]['company_brand'] = isset($v['company']) && $v['company'] ? $v['company']['company_brand'] : 0;
- $list[$k]['name'] = isset($v['employee']) && $v['employee'] ? $v['employee']['opt_name'] : '';
- $list[$k]['nickname'] = isset($v['employee']) && $v['employee'] ? $v['employee']['nickname'] : '';
- $list[$k]['phone'] = isset($v['employee']) && $v['employee'] ? $v['employee']['phone'] : '';
- }
- //dianpu
- $bw[] = ['id', 'in', array_column($list, 'company_brand')];
- $brand = CompanyBrand::where($bw)->column('brand_name', 'id');
- foreach ($list as $k => $v) {
- $list[$k]['brand_name'] = isset($brand[$v['company_brand']]) ? $brand[$v['company_brand']] : '';
- unset($list[$k]['employee']);
- unset($list[$k]['company']);
- }
- }
- $count = OperateLog::with(['employee', 'company'])->where($w)->count();
- return json(['code' => 0, 'data' => $list, 'count' => $count, 'msg' => '获取成功']);
- }
- /**
- * 品牌列表
- */
- public function brand($id)
- {
- $data = CompanyBrand::field('id,logo,brand_name,company_group')->where([['company_group', '=', $id]])->select();
- return json(['code' => 0, 'data' => $data]);
- }
- /**
- * 品牌添加
- */
- public function addBrand()
- {
- $data = $this->request->only(['brand_name', 'logo', 'company_group']);
- CompanyBrand::create($data);
- return json(['code' => 0, 'msg' => '添加成功']);
- }
- /**
- * 品牌编辑
- */
- public function editBrand($id)
- {
- $brand = CompanyBrand::find($id);
- $data = $this->request->only(['brand_name', 'logo', 'company_group']);
- $brand->save($data);
- return json(['code' => 0, 'msg' => '修改成功']);
- }
- /**
- * 集团店面
- */
- public function shop($id)
- {
- $shops = ModelCompany::with(['mini' => function ($query) {
- $query->bind(['type']);
- }])->field('id,company_name,company_brand,start_date,end_date,city,tel,company_group,root_id,mini')
- ->where([
- ['company_group', '=', $id]
- ])->select();
- // 查询店面负责人
- $leaders = Employee::where([['top_one', '=', 1], ['root_id', 'in', array_column($shops->toArray(), 'root_id')]])->column('opt_name', 'root_id');
- foreach ($shops as &$shop) {
- $shop['leader_name'] = $leaders[$shop['root_id']];
- }
- View::assign('shops', $shops);
- return View::fetch();
- }
- /**
- * 添加店面
- */
- public function addShop()
- {
- $param = $this->request->param();
- // $param['end_date'] = ModelCompany::where(['id'=>$param['company_group']])->value('end_date');
- $shop_number = ModelCompany::where([['id', '=', $param['company_group']]])->value('shop_number');
- $count = ModelCompany::where([['company_group', '=', $param['company_group']]])->count();
- if ($count >= $shop_number) return json(['code' => 1, 'msg' => '超出开通店面数量']);
- Db::startTrans();
- try {
- $org_id = Org::insertGetId([
- 'name' => $param['company_name'],
- 'pid' => 0,
- 'level' => 0,
- 'info' => $param['company_name'],
- 'status' => 1
- ]);
- Org::where('id', $org_id)->save(['path' => $org_id . '-']);
- ModelCompany::create([
- 'company_name' => $param['company_name'],
- 'start_date' => date('Y-m-d'),
- 'end_date' => $param['end_date'],
- 'logo' => $param['logo'] ?? '',
- 'root_id' => $org_id,
- 'tel' => $param['tel'],
- 'company_group' => $param['company_group'],
- 'city' => $param['city'],
- 'company_brand' => $param['company_brand'],
- 'province_city' => !empty($param['province_city']) ? $param['province_city'] : '',
- 'province_city_code' => !empty($param['province_city_code']) ? $param['province_city_code'] : ''
- ]);
- $msg = $this->miniInit($org_id, str_rand(6));
- if ($msg) return json(['code' => 1, 'msg' => $msg]);
- Employee::create([
- 'phone' => $param['phone'],
- 'opt_name' => $param['leader_name'],
- 'root_id' => $org_id,
- 'grant_id' => 1,
- 'top_one' => 1
- ]);
- $max_end_date = ModelCompany::where(['company_group' => $param['company_group']])->order('end_date desc')->value('end_date');
- ModelCompany::where(['id' => $param['company_group']])->update(['end_date' => $max_end_date]);
- ConstructionStep::insertAll([
- ['name' => '开工大吉', 'order' => 1, 'root_id' => $org_id],
- ['name' => '前期施工', 'order' => 2, 'root_id' => $org_id],
- ['name' => '中期施工', 'order' => 3, 'root_id' => $org_id],
- ['name' => '后期施工', 'order' => 4, 'root_id' => $org_id],
- ['name' => '竣工', 'order' => 5, 'root_id' => $org_id]
- ]);
- //课程培训默认分类
- TrainClassCate::insertAll([
- ['name' => '销冠分享', 'root_id' => $org_id],
- ['name' => '总裁讲堂', 'root_id' => $org_id],
- ['name' => '营销工具', 'root_id' => $org_id],
- ['name' => '工艺标准', 'root_id' => $org_id],
- ['name' => '营销管理', 'root_id' => $org_id],
- ['name' => '业务技能', 'root_id' => $org_id],
- ['name' => '设计常识', 'root_id' => $org_id],
- ['name' => '产品知识', 'root_id' => $org_id],
- ['name' => '企业文化', 'root_id' => $org_id],
- ['name' => '通用知识', 'root_id' => $org_id],
- ['name' => '其他', 'root_id' => $org_id]
- ]);
- //话术默认使用部门
- TalkskillUsersCate::insertAll([
- ['name' => '业务部', 'root_id' => $org_id, 'show' => 0],
- ['name' => '网销部', 'root_id' => $org_id, 'show' => 0],
- ['name' => '设计师', 'root_id' => $org_id, 'show' => 0],
- ['name' => '客户经理', 'root_id' => $org_id, 'show' => 0],
- ['name' => '市场部', 'root_id' => $org_id, 'show' => 0],
- ['name' => '第三方端', 'root_id' => $org_id, 'show' => 0],
- ['name' => '社群部', 'root_id' => $org_id, 'show' => 0],
- ['name' => '其它', 'root_id' => $org_id, 'show' => 1]
- ]);
- //公司实力默认数据 发展历程 产品介绍 材料实验室 老板访谈 工艺标准 团队承诺 荣誉奖项
- CompanyStrengthCate::insertAll([
- ['name' => '发展历程', 'root_id' => $org_id],
- ['name' => '产品介绍', 'root_id' => $org_id],
- ['name' => '材料实验室', 'root_id' => $org_id],
- ['name' => '老板访谈', 'root_id' => $org_id],
- ['name' => '工艺标准', 'root_id' => $org_id],
- ['name' => '团队承诺', 'root_id' => $org_id],
- ['name' => '荣誉奖项', 'root_id' => $org_id]
- ]);
- //话术默认一级和二级分类
- $cates = [
- '开场邀约' => ['直播活动', '样板征集', '团购活动', '量房设计'],
- '添加微信' => ['加微验证', '加微短信', '电话加微'],
- '引导挖需' => ['基础信息', '谁来做主', '过往经验', '竞品情况', '装修需求'],
- '建立信任' => ['企业文化', '产品模式', '客户见证', '设计实力', '材料实力', '施工实力', '性价比优', '售后承诺'],
- '产品介绍' => ['产品内容', '产品优势', '装修流程'],
- '异议处理' => ['价格问题', '考虑问题', '对比问题', '不急问题'],
- '其他' => []
- ];
- $saves = [];
- foreach ([$org_id] as $v) {
- foreach ($cates as $k2 => $v2) {
- $psave = [
- 'pid' => 0,
- 'type' => 'cate',
- 'root_id' => $v,
- 'name' => $k2
- ];
- $pid = TalkskillCates::insertGetId($psave);
- $save = [];
- foreach ($v2 as $k3 => $v3) {
- $save[] = [
- 'pid' => $pid,
- 'type' => 'cate',
- 'root_id' => $v,
- 'name' => $v3
- ];
- }
- if ($save) (new TalkskillCates())->saveAll($save);
- unset($save);
- unset($psave);
- }
- }
- //公司实力默认数据 发展历程 产品介绍 材料实验室 老板访谈 工艺标准 团队承诺 荣誉奖项
- TalkskillCates::insertAll([
- ['name' => '毛坯期房', 'type' => 'house_type', 'root_id' => $org_id],
- ['name' => '毛坯现房', 'type' => 'house_type', 'root_id' => $org_id],
- ['name' => '毛坯准现房', 'type' => 'house_type', 'root_id' => $org_id],
- ['name' => '老房翻新', 'type' => 'house_type', 'root_id' => $org_id],
- ['name' => '精装房期房', 'type' => 'house_type', 'root_id' => $org_id],
- ['name' => '精装房准现房', 'type' => 'house_type', 'root_id' => $org_id],
- ['name' => '精装房现房', 'type' => 'house_type', 'root_id' => $org_id]
- ]);
- } catch (Exception $e) {
- // 回滚事务
- Db::rollback();
- return json(['code' => 1, 'msg' => $e->getMessage()]);
- }
- Db::commit();
- return json(['code' => 0, 'msg' => '添加成功']);
- }
- public function editShop($id)
- {
- $param = $this->request->only(['company_name', 'tel', 'city', 'company_brand', 'leader_name', 'end_date','mini','province_city'=>'','province_city_code'=>'','phone']);
- $data = ModelCompany::findOrEmpty($id);
- if ($data->isEmpty()) return json(['code' => 1, 'msg' => '保存失败,数据不存在']);
- $old = $data->mini;
- $data->save($param);
- if ($param['mini'] != $old) $this->miniInit($data->root_id);
-
- //Employee::where([['top_one', '=', 1], ['root_id', '=', $data->root_id]])->update(['opt_name' => $param['leader_name']]);
- $empdata = Employee::where([['top_one', '=', 1], ['root_id', '=', $data->root_id]])->find();
- $empdata->opt_name = $param['leader_name'];
- if(!empty($param['phone']) && $param['phone'] != $empdata['phone']){
- $check = Employee::where([['root_id', '=', $data->root_id],['phone','=',cypherphone(trim($param['phone']))]])->find();
- if(!empty($check)){
- $check->grant_id = 1;
- $check->top_one = 1;
- $check->save();
- $empdata->top_one = 0;
- $empdata->grant_id = 0;
- $empdata->save();
- return json(['code' => 0, 'msg' => '保存成功']);
- }
- $empdata->phone = $param['phone'];
- }
- $empdata->save();
- $max_end_date = ModelCompany::where(['company_group' => $data->company_group])->order('end_date desc')->value('end_date');
- ModelCompany::where(['id' => $data->company_group])->update(['end_date' => $max_end_date,'province_city'=>$param['province_city'],'province_city_code'=>$param['province_city_code']]);
- return json(['code' => 0, 'msg' => '保存成功']);
- }
- /**
- * 企微设置列表
- */
- public function wework_index()
- {
- $company_id = input('company_id', '', 'intval');
- $list = WeworksingleCompanySetting::where('company_id', '=', $company_id)->select();
- View::assign('company_id', $company_id);
- View::assign('list', $list);
- return View::fetch();
- }
- public function wework()
- {
- if (!request()->isAjax()) {
- $id = input('id', '', 'intval');
- $company_id = input('company_id', '', 'intval');
- View::assign('company_id', $company_id);
- $have_setting = true;
- if ($id) {
- $setting = WeworksingleCompanySetting::where('id', '=', $id)->findOrEmpty();
- if ($setting->isEmpty()) {
- $have_setting = false;
- }
- } else {
- $have_setting = false;
- }
- if (!$have_setting) {
- $ticket = md5(time());
- $setting['company_id'] = $company_id;
- $setting['ticket'] = $ticket;
- $setting['corp_id'] = '';
- $setting['agentid'] = '';
- $setting['agent_secret'] = '';
- $setting['receive_token'] = '';
- $setting['receive_aes_key'] = '';
- $setting['contact_secret'] = '';
- $setting['contact_token'] = '';
- $setting['contact_aes_key'] = '';
- $setting['customer_secret'] = '';
- $setting['customer_token'] = '';
- $setting['customer_aes_key'] = '';
- $setting['chat_secret'] = '';
- $setting['chat_token'] = '';
- $setting['chat_aes_key'] = '';
- $setting['chat_private_key'] = '';
- $setting['verify_file'] = '';
- $setting['verify_content'] = '';
- $result = WeworksingleCompanySetting::create($setting);
- $id = $result->id;
- } else {
- $ticket = $setting['ticket'];
- }
- View::assign('id', $id);
- View::assign('setting', $setting);
- // 应用主页
- $index_url = request()->domain() . '/weworksingle.html#/loading?ticket=' . $ticket;
- View::assign('index_url', $index_url);
- //应用接收消息回调链接
- $agent_receive_url = request()->domain() . '/weworksingle/verifyurl?ticket=' . $ticket;
- View::assign('agent_receive_url', $agent_receive_url);
- // 客户变更回调链接
- $customer_receive_url = request()->domain() . '/weworksingle/customerverifyurl?ticket=' . $ticket;
- View::assign('customer_receive_url', $customer_receive_url);
- // 通讯录变更回调链接
- $contact_receive_url = request()->domain() . '/weworksingle/contactverifyurl?ticket=' . $ticket;
- View::assign('contact_receive_url', $contact_receive_url);
- return View::fetch();
- } else {
- $id = input('id', '', 'intval');
- $param = $this->request->param();
- $find = WeworksingleCompanySetting::where('id', '=', $id)->findOrEmpty();
- if ($find->isEmpty()) {
- if (!empty($param['company_id'])) {
- $data['company_id'] = $param['company_id'];
- }
- $data['corp_id'] = $param['corp_id'] ?? '';
- $data['ticket'] = $param['ticket'] ?? '';
- $data['agentid'] = $param['agentid'] ?? '';
- $data['agent_secret'] = $param['agent_secret'] ?? '';
- $data['receive_token'] = $param['receive_token'] ?? '';
- $data['receive_aes_key'] = $param['receive_aes_key'] ?? '';
- $data['contact_secret'] = $param['contact_secret'] ?? '';
- $data['contact_token'] = $param['contact_token'] ?? '';
- $data['contact_aes_key'] = $param['contact_aes_key'] ?? '';
- $data['customer_secret'] = $param['customer_secret'] ?? '';
- $data['customer_token'] = $param['customer_token'] ?? '';
- $data['customer_aes_key'] = $param['customer_aes_key'] ?? '';
- $data['verify_file'] = $param['verify_file'] ?? '';
- $data['verify_content'] = $param['verify_content'] ?? '';
- $result = WeworksingleCompanySetting::create($data);
- if ($result) {
- return json(['code' => 0, 'msg' => '操作成功']);
- } else {
- return json(['code' => 1, 'msg' => '操作失败']);
- }
- } else {
- if (!empty($param['corp_id'])) {
- $find->corp_id = $param['corp_id'];
- }
- if (!empty($param['agentid'])) {
- $find->agentid = $param['agentid'];
- }
- if (!empty($param['agent_secret'])) {
- $find->agent_secret = $param['agent_secret'];
- }
- if (!empty($param['receive_token'])) {
- $find->receive_token = $param['receive_token'];
- }
- if (!empty($param['receive_aes_key'])) {
- $find->receive_aes_key = $param['receive_aes_key'];
- }
- if (!empty($param['contact_secret'])) {
- $find->contact_secret = $param['contact_secret'];
- }
- if (!empty($param['contact_token'])) {
- $find->contact_token = $param['contact_token'];
- }
- if (!empty($param['contact_aes_key'])) {
- $find->contact_aes_key = $param['contact_aes_key'];
- }
- if (!empty($param['customer_secret'])) {
- $find->customer_secret = $param['customer_secret'];
- }
- if (!empty($param['customer_token'])) {
- $find->customer_token = $param['customer_token'];
- }
- if (!empty($param['customer_aes_key'])) {
- $find->customer_aes_key = $param['customer_aes_key'];
- }
- if (!empty($param['verify_file'])) {
- $find->verify_file = $param['verify_file'];
- }
- if (!empty($param['verify_content'])) {
- $find->verify_content = $param['verify_content'];
- }
- $result = $find->save();
- if ($result) {
- return json(['code' => 0, 'msg' => '操作成功']);
- } else {
- return json(['code' => 1, 'msg' => '操作失败']);
- }
- }
- }
- }
- /**
- * 设置信息一键复制(一个企业微信多家店面)
- */
- public function wework_copy()
- {
- $company_id = input('company_id', '', 'intval');
- if (!$this->request->isAjax()) {
- $company_group = CompanyModel::where('id', '=', $company_id)->value('company_group');
- $company_list = [];
- if ($company_group) {
- $company_list = CompanyModel::where([['company_group', '=', $company_group], ['id', '<>', $company_id]])->select()->toArray();
- }
- foreach ($company_list as $k => $v) {
- $find = WeworksingleCompanySetting::where('company_id', '=', $v['id'])->find();
- if (empty($find)) {
- unset($company_list[$k]);
- }
- }
- View::assign('data', array_values($company_list));
- View::assign('company_id', $company_id);
- return View::fetch();
- } else {
- $copy_id = input('copy_id', '', 'intval');
- $setting = WeworksingleCompanySetting::where('company_id', '=', $copy_id)->findOrEmpty();
- if ($setting->isEmpty()) {
- return json(['code' => 1, 'msg' => '复制失败,企业配置不存在']);
- }
- $setting = $setting->toArray();
- unset($setting['id']);
- $setting['company_id'] = $company_id;
- $result = WeworksingleCompanySetting::create($setting);
- if ($result !== false) {
- return json(['code' => 0, 'msg' => '复制成功']);
- } else {
- return json(['code' => 1, 'msg' => '复制失败']);
- }
- }
- }
- /**
- * 删除企业微信配置
- */
- public function wework_delete()
- {
- $id = input('id', '', 'intval');
- $find = WeworksingleCompanySetting::find($id);
- if (empty($find)) {
- return json(['code' => 0, 'msg' => '删除成功']);
- }
- $result = $find->delete();
- if ($result) {
- return json(['code' => 0, 'msg' => '删除成功']);
- } else {
- return json(['code' => 1, 'msg' => '删除失败']);
- }
- }
- /**
- * 设置企业微信时上传校验文件
- */
- public function wework_upload()
- {
- $file = request()->file('file');
- $file_name = $file->getOriginalName();
- $value = file_get_contents($file->getPathname());
- if ($value) {
- return json(['code' => 0, 'msg' => '上传成功', 'data' => ['name' => $file_name, 'content' => $value]]);
- } else {
- return json(['code' => 1, 'msg' => '上传失败']);
- }
- }
- /**
- * 新增店铺新页面
- */
- public function new_add_shop()
- {
- $company_id = input('company_id',0);
- View::assign('company_id', $company_id);
- $miniprogram = Wechat::field('id, type')->select();
- View::assign('miniprogram', $miniprogram);
- return View::fetch();
- }
- /**
- * 编辑店铺新页面
- */
- public function new_edit_shop()
- {
- $id = input('id',0);
- View::assign('id', $id);
- $company_id = input('company_id',0);
- View::assign('company_id', $company_id);
- $company = ModelCompany::where('id', $id)->find();
- $empdata = Employee::where([['top_one', '=', 1], ['root_id', '=', $company->root_id]])->field('phone,opt_name')->find();
- $company['phone'] = $empdata['phone'];
- $company['leader_name'] = $empdata['opt_name'];
- // $company['phone'] = Employee::where([['top_one', '=', 1], ['root_id', '=', $company->root_id]])->value('phone');
- // $company['leader_name'] = Employee::where([['top_one', '=', 1], ['root_id', '=', $company->root_id]])->value('opt_name');
- View::assign('data', $company);
- $miniprogram = Wechat::field('id, type')->select();
- View::assign('miniprogram', $miniprogram);
- return View::fetch();
- }
- }
|