123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588 |
- <?php
- declare(strict_types=1);
- namespace app\mobile\controller;
- use app\model\Employee;
- use app\model\User;
- use think\facade\Request;
- use app\model\TalkskillCates;
- use app\model\TalkskillSuccess;
- use app\model\TalkskillUsersCate;
- use app\model\Talkskill as TalkskillModel;
- use app\model\TalkskillHotKeyword;
- use app\model\TalkskillComment;
- use app\model\TalkskillChosen;
- use app\model\TalkskillContent;
- use app\model\TalkskillPraise;
- use app\model\TalkskillViewLog;
- use app\model\UserCollect;
- use app\model\CreditsLog;
- use app\model\CreditsSetting;
- use Exception;
- use think\facade\Db;
- use app\model\Credits;
- class Talkskill extends Base
- {
- /**
- * 精选话术分类
- */
- public function getChosenCate()
- {
- $where = [
- // ['scene_type','=','chosen'],//不唯一 都是精选话术,一份分类有chosen,二级分类没有
- ['root_id','=',$this->rootId],
- ['show','<>',1],
- ['type','=','cate']
- ];
- $list = TalkskillCates::where($where)->field('pid,name,id,scene_type')->select()->toArray();
- $res = [];
- foreach ($list as $key => $value) {
- if($value['pid']==0 && $value['scene_type']=='chosen'){
- $value['child'] = [];
- foreach ($list as $item) {
- if ($item['pid'] && $value['id'] == $item['pid']) $value['child'][] = $item;
- }
- $res[] = $value;
- }
- }
- return json(['code'=>0,'data'=>$res,'msg'=>'']);
- }
- /*
- * 成功案例列表
- */
- public function successList()
- {
- $param = Request::only(['page'=>1, 'limit'=>10, 'keyword'=>'', 'house_type'=>0, 'user_cate'=>0, 'order'=>'', 'cate1'=>0]);
- $where = [
- ['root_id', '=', $this->rootId],
- ['del', '=', 0]
- ];
- if($param['keyword']) $where[] = ['title', 'like', '%'.$param['keyword'].'%'];
- if ($param['cate1']) $where[] = ['cate1', '=',$param['cate1']];
- if($param['house_type']) $where[] = ['house_type','find in set',$param['house_type']];
- if($param['user_cate']) $where[] = ['user_cate','find in set',$param['user_cate']];
- $order = $param['order'] ?: 'addtime desc';
- $array = TalkskillSuccess::where($where)->field('id,title,use_count,view_times,addtime,cate1')->order($order)->page((int)$param['page'], (int)$param['limit'])->select()->toArray();
- $cates = array_column($array,'cate1');
- $cate = TalkskillCates::where([['id','in',$cates],['root_id', '=', $this->rootId]])->column('name','id');
- foreach ($array as $key => $value) {
- $array[$key]['addtime'] = date('Y-m-d',strtotime($value['addtime']));
- $array[$key]['cate1_name'] = isset($cate[$value['cate1']]) ? $cate[$value['cate1']] : '';
-
- }
- return json(['code' => 0, 'msg' => '获取成功', 'data' => $array]);
- }
- /*
- * 话术列表
- */
- public function lists()
- {
- $param = Request::only(['page'=>10,'limit'=>10, 'user_cate'=>0,'keyword'=>'','cate1'=>'','house_type'=>'','order'=>'id desc', 'messy'=>0]);
- $token['root_org'] = $this->rootId;
- $token['employee_id'] = $this->employeeId;
- $token['uid'] = $this->uid;
- $where = [
- ['del', '=', 0],
- ['root_id', '=', $token['root_org']],
- ['approve', '=', 1]
- ];
- if ($param['cate1']) $where[] = ['cate1', '=',$param['cate1']];
- if ($param['user_cate']) $where[] = ['user_cate','find in set',$param['user_cate']];
- if (!empty($param['house_type'])) $where[] = ['house_type','find in set',$param['house_type']];
- $order = $param['order'] ?: 'id desc';
- //关键词筛选
- if (!empty(trim($param['keyword']))) {
- $hot = TalkskillHotKeyword::where(['root_id' => $token['root_org'], 'keyword' => trim($param['keyword'])])->find();
- if (!empty($hot)) {
- $hot->use_count = $hot->use_count + 1;
- $hot->save();
- } else {
- TalkskillHotKeyword::create(['root_id' => $token['root_org'], 'keyword' => trim($param['keyword'])]);
- }
- $where[] = ['title', 'like', '%' . trim($param['keyword']) . '%'];
- }
- //仅展示0回答
- if (isset($param['messy']) && $param['messy'] == 1) {
- $where[] = ['commentCount', '=', 0];
- $where[] = ['content', '=', ''];
- }
- $data = TalkskillModel::where($where)->with(['TalkskillComment' => function ($query) use ($token) {
- $query->where('root_id='.$token['root_org'].' and approve=1')->order('use desc,praise desc,id asc')
- ->field('taid,uid,comments');
- }])->field('id,title,content,label,use_count,addtime,approve,imgs,media_id,weixin_media,user_cate,house_type,cate1,cate2');
- $list = $data->where($where)->page((int)$param['page'],(int)$param['limit'])->order($order)->select();
- $count = $data->where($where)->count();
- foreach ($list as &$val) {
- $val['y_imgs'] = $val['imgs'] ? $val->getData('imgs') : '';
- }
- $list = $list->toArray();
- $column_talkskill_id = array_column($list, 'id');
- $comment = TalkskillComment::where([['taid', 'in', $column_talkskill_id], ['root_id', '=', $token['root_org']]])->field('taid,addtime')->group('taid')->order('addtime desc')->column('addtime', 'taid');
- $arr = [0 => '待审核', 1 => '审核通过', 2 => '被驳回'];
- foreach ($list as &$val) {
- //话术回答展示顺序,官方回答,员工回答使用最多,点赞最多,先回答
- if (!$val['content'] && $val['TalkskillComment']) {
- $val['content'] = $val['TalkskillComment'][0]['comments'];
- }
- $val['TalkskillComment'] = $val['TalkskillComment'] ? count(array_unique(array_column($val['TalkskillComment'], 'uid'))) : 0;
- $val['status'] = $arr[$val['approve']];
- unset($e_where);
- $e_where[] = ['taid', '=', $val['id']];
- $e_where[] = ['root_id', '=', $token['root_org']];
- $comment_count = TalkskillComment::where($e_where)->where(function ($query) use ($token) {
- $query->where('approve=1 or (uid=' . $token['uid'] . ' and approve=0)');
- })->count();
- $val['comment_count'] = $comment_count;
- }
- return json(['code' => 0, 'msg' => '获取成功', 'data' => $list, 'count' => $count]);
- }
- /*
- * 话术搜索条件下拉
- */
- public function searchSelect()
- {
- //房屋类型
- $houseTypeWhere = [
- ['pid','=',0],
- ['type','=','house_type'],
- ['root_id','=',$this->rootId]
- ];
- $data['house_type'] = TalkskillCates::where($houseTypeWhere)->field('name,id')->order('id asc')->select()->toarray();
- //适用人群列表
- $UserCateWhere = [
- ['root_id' ,'=', $this->rootId]
- ];
- $data['user'] = TalkskillUsersCate::where($UserCateWhere)->field('name,id')->select()->toarray();
- //精选话术场景,普通话术场景
- //查询关联一级话术数量
- $talkskillArr = TalkskillModel::where([['del', '=', 0], ['root_id', '=', $this->rootId], ['approve', '=', 1]])->group('cate1')->column('count(id)','cate1');
- //查询成功案例关联一级话术数量
- $talkskillSuccessArr = TalkskillSuccess::where([['del', '=', 0], ['root_id', '=', $this->rootId]])->group('cate1')->column('count(id)','cate1');
- $cate = [
- ['type','=','cate'],
- ['root_id','=',$this->rootId],
- ['pid','=',0]
- ];
- $data['scene'] = $data['success_scene'] = [];
- $cate = TalkskillCates::where($cate)->field('pid,name,id,scene_type,show')->order('id asc')->select()->toarray();
- foreach ($cate as $key => $value) {
- if ($value['scene_type']=='chosen' && $value['show']!=1) {
- $value['count'] = isset($talkskillSuccessArr[$value['id']]) ? $talkskillSuccessArr[$value['id']] : 0;
- $data['success_scene'][] = $value;
- }elseif ($value['scene_type']!='chosen') {
- $value['count'] = isset($talkskillArr[$value['id']]) ? $talkskillArr[$value['id']] : 0;
- $data['scene'][] = $value;
- }
- }
- return json(['code' => 0, 'msg' => '获取成功', 'data' => $data]);
- }
- /*
- * 匿名提问
- */
- public function submitQuestions()
- {
- $questions = Request::only(['questions'=>'', 'imgs'=>'']);
- $data = [
- 'title' => trim($questions['questions']),
- 'root_id' => $this->rootId,
- 'type' => 'submit',
- 'employee_id' => $this->employeeId,
- 'content' => '',
- 'imgs' => isset($questions['imgs']) && $questions['imgs'] ? $questions['imgs'] : ''
- ];
- TalkskillModel::create($data);
- return json(['code' => 0, 'msg' => '提交成功']);
- }
- /*
- * 上传话术下拉选框
- */
- public function addTalkskillSelect()
- {
- //房屋类型
- $houseTypeWhere = [
- ['pid','=',0],
- ['type','=','house_type'],
- ['root_id','=',$this->rootId]
- ];
- $data['house_type'] = TalkskillCates::where($houseTypeWhere)->field('name,id')->order('id asc')->select()->toarray();
- //适用人群列表
- $UserCateWhere = [
- ['root_id' ,'=', $this->rootId]
- ];
- $data['user'] = TalkskillUsersCate::where($UserCateWhere)->field('name,id')->select()->toarray();
- //普通话术场景
- $cate = [
- ['type','=','cate'],
- ['root_id','=',$this->rootId],
- ['pid','=',0],
- ['scene_type','=','']
- ];
- $cate1 = TalkskillCates::where($cate)->order('id desc')->column('id,name');
- $cate2 = TalkskillCates::where([['pid','in',array_column($cate1,'id')]])->column('id,pid,name');
- $cate3 = [];
- foreach ($cate2 as $key => $value) {
- $cate3[$value['pid']][] = $value;
- }
- foreach ($cate1 as $key2 => $value2) {
- $cate1[$key2]['child'] = isset($cate3[$value2['id']]) ? $cate3[$value2['id']] : [];
- }
- $data['scene'] = $cate1;
- return json(['code' => 0, 'msg' => '获取成功', 'data' => $data]);
- }
- /*
- * 上传话术
- */
- public function submitTalkskill()
- {
- $questions = Request::only(['user_cate'=>'','title'=>'', 'content'=>'', 'imgs'=>'','house_type'=>'','cate1'=>'','cate2'=>'']);
- $data = [
- 'title' => $questions['title'],
- 'root_id' => $this->rootId,
- 'type' => 'share',
- 'employee_id' => $this->employeeId,
- 'content' => $questions['content'],
- 'imgs' => isset($questions['imgs']) && $questions['imgs'] ? $questions['imgs'] : '',
- 'approve' => 0,
- 'user_cate' => $questions['user_cate'],
- 'house_type' => $questions['house_type'],
- 'cate1' => $questions['cate1'],
- 'cate2' => $questions['cate2'],
- 'imgs' => $questions['imgs']
- ];
- TalkskillModel::create($data);
- return json(['code' => 0, 'msg' => '提交成功']);
- }
- /*
- * 精选话术、成功案例的话术列表
- */
- public function chosenAndSuccessList()
- {
- $param = Request::only(['id'=>0, 'page'=>1, 'limit'=>10, 'house_type'=>0, 'user_cate'=>0, 'talkskill_type', 'cate2'=>0,'keyword'=>'']);
- if($param['talkskill_type'] == 'chosen'){
- if(!$param['cate2']) return json(['code' => 0, 'msg' => '获取成功', 'data' => []]);
- }else{
- if(!$param['id']) return json(['code' => 0, 'msg' => '获取成功', 'data' => []]);
- }
- $where = [
- ['root_id', '=', $this->rootId],
- ['del', '=', 0]
- ];
- if ($param['keyword']) {
- $where1 = array_merge($where,[['title','like','%'.$param['keyword'].'%']]);
- $ids1 = ($param['talkskill_type']=='chosen') ? TalkskillChosen::where($where1) : TalkskillSuccess::where($where1);
- $ids1 = $ids1->column('id');
- $ids2 = TalkskillContent::where([
- ['root_id', '=', $this->rootId],
- ['talkskill_type', '=', $param['talkskill_type']],
- ['content', 'like', '%'.trim($param['keyword']).'%']
- ])->group('talkskill_id')->column('talkskill_id');
- if(empty($ids1) && empty($ids2)) return json(['code' => 0, 'msg' => '获取成功', 'data' => []]);
- $where[] = ['id','in',array_merge($ids1,$ids2)];
- }
- $where[] = ($param['talkskill_type']=='chosen') ? ['cate2','find in set',$param['cate2']] : ['id', '=', $param['id']];
- if(!empty($param['house_type'])) $where[] = ['house_type','find in set',$param['house_type']];
- if(!empty($param['user_cate'])) $where[] = ['user_cate','find in set',$param['user_cate']];
- $data = ($param['talkskill_type']=='chosen') ? TalkskillChosen::where($where) : TalkskillSuccess::where($where);
- $data = $data->field('id,title,view_times,use_count')->page((int)$param['page'], (int)$param['limit'])->order('id desc')->select()->toArray();
- $column_id = array_column($data,'id');
- $content = TalkskillContent::where([['talkskill_id', 'in', $column_id], ['talkskill_type', '=', $param['talkskill_type']]])->field('talkskill_id,content,type,img')->order('addtime asc')->select()->toArray();
- foreach($data as &$item)
- {
- $item['child'] = [];
- foreach($content as $key=>$val)
- {
- if($val['talkskill_id'] == $item['id'])
- {
- $val['img'] = $val['img'] ? explode(',',$val['img']) : '';
- if(!empty($val['img'])){
- foreach($val['img'] as &$img){
- $img = 'https://' . config('app.ali_oss_bindurl') . '/' . $img;
- }
- }
- $item['child'][] = $val;
- }
- }
- }
- //使用次数增加
- $model = $param['talkskill_type'] == 'chosen' ? TalkskillChosen::where([['id', 'in', $column_id]]) : TalkskillSuccess::where([['id', 'in', $column_id]]);
- $model->inc('view_times')->update();
- return json(['code' => 0, 'msg' => '获取成功', 'data' => $data]);
- }
- /*
- * 话术评论
- */
- public function addComment()
- {
- $param = Request::only(['content', 'taid']);
- $check = TalkskillModel::where([['root_id','=',$this->rootId],['id','=',$param['taid']]])->field('id')->findOrEmpty();
- if($check->isEmpty()) return json(['code' => 1, 'msg' => '回答失败','data'=>'回答失败']);
- $data = [
- 'uid' => $this->uid,
- 'taid' => $param['taid'],
- 'root_id' => $this->rootId,
- 'comments' => $param['content']
- ];
- TalkskillComment::insert($data);
- return json(['code' => 0, 'msg' => '回答成功']);
- }
- /*
- * 话术回答列表
- */
- public function commentList()
- {
- $param = Request::only(['taid', 'page']);
- $token['root_org'] = $this->rootId;
- $token['employee_id'] = $this->employeeId;
- $token['uid'] = $this->uid;
- $where[] = ['taid', '=', $param['taid']];
- $where[] = ['root_id', '=', $token['root_org']];
- $data = TalkskillComment::with(['user'])->where(function ($query) use ($token) {
- $query->where('approve=1 or (uid=' . $token['uid'] . ' and approve=0)');
- })->where($where)->page((int)$param['page'], 10)->order(['approve' => 'asc', 'use' => 'desc', 'praise' => 'desc'])->select()->toArray();
- $column_talkskillcomment_id = array_column($data, 'id');
- $column_talkskillcomment_uid = array_column($data, 'uid');
- $praise = TalkskillPraise::where([['root_id', '=', $token['root_org']], ['content_id', 'in', $column_talkskillcomment_id], ['user_id', '=', $token['uid']]])->column('user_id', 'content_id');
- $employee = Employee::where([['uid', 'in', $column_talkskillcomment_uid], ['root_id', '=', $token['root_org']]])->column('name', 'uid');
- $state = Employee::where([['uid', 'in', $column_talkskillcomment_uid], ['root_id', '=', $token['root_org']]])->column('state', 'uid');
- foreach ($data as &$val) {
- $val['ispraise'] = isset($praise[$val['id']]) ? 1 : 0;
- $val['name'] = isset($employee[$val['uid']]) ? $employee[$val['uid']] : '暂无';
- $val['state'] = isset($state[$val['uid']]) ? $state[$val['uid']] : '离职';
- if (strpos($val['state'], "离职") !== false) {
- $val['name'] = '匿名用户';
- $val['headimgurl'] = '';
- }
- }
- $count = TalkskillComment::where($where)->where(function ($query) use ($token) {
- $query->where('approve=1 or (uid=' . $token['uid'] . ' and approve=0)');
- })->count();
- return json(['code' => 0, 'msg' => '获取成功', 'data' => $data, 'count' => $count]);
- }
- /*
- * 百问百答详情
- */
- public function talkskillRead($id)
- {
- $data = TalkskillModel::where('id', $id)->field('use_count,id,title,content,label,commentCount,imgs,media_id,weixin_media,user_cate,house_type,cate1,cate2')->find();
- //是否收藏
- $collect = UserCollect::where(['user_id' => $this->uid, 'content_id' => $id, 'content_type' => 'talkskill'])->value('id');
- $data['collect'] = $collect ? 1 : 0;
- $this->addTalkskillViewLog('talkskill');
-
- return json(['code' => 0, 'msg' => '获取成功', 'data' => $data]);
- }
- /*
- * 增加话术浏览记录
- */
- private function addTalkskillViewLog($type)
- {
- TalkskillViewLog::create([
- 'root_id' => $this->rootId,
- 'org_id' => Employee::where('id',$this->employeeId)->value('org_id'),
- 'employee_id' => $this->employeeId,
- 'type' => $type
- ]);
- return true;
- }
- /**
- * 点赞
- */
- public function praise($id)
- {
- $rs = TalkskillPraise::where(['user_id' => $this->uid, 'root_id' => $this->rootId, 'content_id' => $id])->count();
- if ($rs > 0) return json(['code' => 1, 'msg' => '您已点赞']);
- TalkskillPraise::create([
- 'user_id' => $this->uid,
- 'root_id' => $this->rootId,
- 'content_id' => $id
- ]);
- TalkskillComment::where('id', $id)->inc('praise')->update();
- return json(['code' => 0, 'msg' => '点赞成功']);
- }
- /**
- * 取消点赞
- */
- public function praiseCancel($id)
- {
- $rs = TalkskillPraise::where(['user_id' => $this->uid, 'root_id' => $this->rootId, 'content_id' => $id])->find();
- if (!$rs) return json(['code' => 1, 'msg' => '取消点赞失败']);
- $rs->delete();
- $praise = TalkskillComment::where('id', $id)->value('praise');
- if ($praise > 0) {
- TalkskillComment::where('id', $id)->dec('praise')->update();
- }
- return json(['code' => 0, 'msg' => '取消成功']);
- }
- /*
- * 复制话术
- * type->use_comment:复制用户的,use_admin:复制后台的
- */
- public function useTalkskill()
- {
- $param = Request::only(['type', 'id']);
- $token['root_org'] = $this->rootId;
- $token['employee_id'] = $this->employeeId;
- Db::startTrans();
- try {
- $end = true;
- $type = $param['type'] == 'use_comment' ? 1 : 0;
- $where = [];
- $where[] = ['type', '=', $type];
- $where[] = ['talkskill_id', '=', $param['id']];
- $where[] = ['root_id', '=', $token['root_org']];
- $where[] = ['employee_id', '=', $token['employee_id']];
- $credits_log = CreditsLog::where($where)->select()->toArray();
- if (!$credits_log) {
- $save['talkskill_id'] = $param['id'];
- $save['root_id'] = $token['root_org'];
- $save['employee_id'] = $token['employee_id'];
- $save['type'] = $type;
- $save['addtime'] = date('Y-m-d H:i:s', time());
- CreditsLog::insert($save);
- //增加使用人次
- if ($param['type'] == 'use_comment') {
- TalkskillComment::where(['id' => $param['id'], 'root_id' => $token['root_org']])->inc('use')->update();
- } else {
- TalkskillModel::where(['id' => $param['id'], 'root_id' => $token['root_org']])->inc('use_count')->update();
- }
- } else {
- $end = false;
- // Db::commit();
- // return json(['code' => 0, 'msg' => '复制成功','data'=>$this->get_credits($param)]);
- }
- if ($end) {
- //复制自己上传的话术或者后台添加的话术或者官方回答或非审核通过,不得积分
- if ($param['type'] != 'use_comment') {
- $info = TalkskillModel::where(['id' => $param['id'], 'root_id' => $token['root_org']])->findOrEmpty();
- if ($info->isEmpty() || $info['employee_id'] == 0 || $info['type'] == 'admin' || $info['type'] == 'submit' || $info['employee_id'] == $token['employee_id'] || $info['approve'] != 1) {
- $end = false;
- // Db::commit();
- // return json(['code' => 0, 'msg' => '复制成功','data'=>$this->get_credits($param)]);
- }
- } else { //复制自己添加的评论不得积分复制没有审核通过的评论不得积分
- $info = TalkskillComment::where(['id' => $param['id'], 'root_id' => $token['root_org']])->findOrEmpty();
- $eid = Employee::where([['id', '=', $token['employee_id']], ['root_id', '=', $token['root_org']]])->findOrEmpty();
- if ($info->isEmpty() || $eid->isEmpty() || $info['uid'] == $eid['uid'] || $info['approve'] != 1) {
- $end = false;
- // Db::commit();
- // return json(['code' => 0, 'msg' => '复制成功','data'=>$this->get_credits($param)]);
- }
- $info['employee_id'] = Employee::where([['uid', '=', $info['uid']], ['root_id', '=', $token['root_org']]])->value('id');
- }
- }
-
- if ($end) {
- //未计算积分的被使用次数
- $where[] = ['status', '=', 0];
- $credits_log = CreditsLog::where($where)->select()->toArray();
- $count = count($credits_log);
- if ($count == 0) {
- $end = false;
- // Db::commit();
- // return json(['code' => 0, 'msg' => '复制成功','data'=>$this->get_credits($param)]);
- }
- }
-
- if ($end) {
- //查询规则
- if ($param['type'] == 'use_comment') {
- $rule = CreditsSetting::where([['root_id', '=', $token['root_org']], ['code', '=', 'talkskill_person2']])->value('value');
- $rule = $rule ? json_decode($rule, true) : ['person2' => 1, 'credits2' => 1];
- $rule = ['person' => $rule['person2'], 'credits' => $rule['credits2']];
- } else {
- $rule = CreditsSetting::where([['root_id', '=', $token['root_org']], ['code', '=', 'talkskill_person1']])->value('value');
- $rule = $rule ? json_decode($rule, true) : ['person1' => 1, 'credits1' => 1];
- $rule = ['person' => $rule['person1'], 'credits' => $rule['credits1']];
- }
- //计算积分
- if ($count >= $rule['person']) {
- $credits = new Credits();
- $save = [];
- $credits->employee_id = $info['employee_id'];
- $credits->root_id = $token['root_org'];
- $credits->credits = $rule['credits'];
- $credits->type = 0;
- $credits->json = $param['id'];
- $credits->remark = ($param['type'] == 'use_comment') ? '话术评论被使用' : '话术被使用';
-
- $credits->save();
-
- $id = $credits->id;
- $c_where[] = ['employee_id', '=', $info['employee_id']];
- $c_where[] = ['root_id', '=', $token['root_org']];
- $c_where[] = ['type', '=', 0];
- $sum = Credits::where($c_where)->sum('credits');
- Credits::where([['id', '=', $id]])->update(['sum' => $sum]);
- CreditsLog::where([['id', 'in', array_column($credits_log, 'id')]])->update(['status' => 1]);
- }
- }
-
- Db::commit();
- } catch (Exception $e) {
- // 回滚事务
- Db::rollback();
- return json(['code' => 1, 'msg' => $e->getMessage(), 'data' => $this->get_credits($param)]);
- }
- return json(['code' => 0, 'msg' => '复制成功', 'data' => $this->get_credits($param)]);
- }
- public function get_credits($param)
- {
- $token['root_org'] = $this->rootId;
- if ($param['type'] == 'use_comment') {
- $count = TalkskillComment::where(['id' => $param['id'], 'root_id' => $token['root_org']])->value('use');
- } else {
- $count = TalkskillModel::where(['id' => $param['id'], 'root_id' => $token['root_org']])->value('use_count');
- }
- return $count;
- }
- }
|