with(['content'])->page($page, 10)->order('share_time desc')->select(); return json(['code' => self::success, 'data' => $data, 'page' => $page]); } /** * 分享成功回调 */ public function addlog($type, $id, $other_data = '') { $old_type = $type; $strpos = strpos($type,'_vr'); if ($strpos){ $type = str_replace('_vr', '', $type); } //通过谈单工具、老客户转介绍整个板块分享的不进行验证 if (!in_array($type, ['toolAll', 'customerJsAll', 'weiwang', 'card','company', 'buildingProgress'])) { $class = 'app\\model\\' . ucfirst($type); if (!class_exists($class)) return json(['code' => self::error_msg, 'msg' => '类型不存在']); } $token = $this->request->token; $saveData = []; // 判断分享操作人 // 1,员工分享 if (isset($token['employee_id'])) { $saveData['employee_id'] = $token['employee_id']; } // 2,经纪人/用户 分享 else { // 经纪人查询 $agent_data = AgentUser::where([['uid', '=', $token['uid']], ['root_id', '=', $token['root_org']]])->find(); // 经纪人分享 if (!empty($agent_data)) { $saveData['employee_id'] = $agent_data['agent_employee_id']; $saveData['agent_id'] = $agent_data['id']; } // 被员工分享后的客户 elseif (isset($token['share_employee'])) { $saveData['employee_id'] = $token['share_employee']; } } $saveData['data_id'] = $id ?? 0; $saveData['type'] = ucfirst($old_type); $saveData['other_data'] = $other_data; ShareLog::create($saveData); // 添加分享数量 if (!in_array($type, ['toolAll', 'customerJsAll', 'weiwang', 'card','company','employeeCard','housetype', 'buildingProgress'])) { (new $class())->where(['id' => $id])->inc('shared_times')->update(); // 发送通知消息 $c = (new $class())->find($id); // 发送管理层模板消息 if($c){ $c = $c->toArray(); $title = ''; if(isset($c['title'])) $title = $c['title']; elseif (isset($c['name'])) $title = $c['name']; $msg = ['first'=>'行为通知', 'keyword1'=>'转发素材 ', 'keyword2'=>'员工'.$token['name'] . "转发素材《".$title.'》', 'keyword3'=>date('Y/m/d'), 'remark'=>'请悉知']; TmpMsg::sendMsgToLeader($msg, $token['org_id']); } } if (ucfirst($type) == 'MaterialCase') { $this->use_talkskill($id); } return json(['code' => self::success, 'msg' => '记录添加成功']); } /** * 小程序分享链接 url_scheme */ public function urlscheme() { $param = $this->request->param(); // 存储参数 $data = [ 'content' => json_encode($param), 'type' => 'share' ]; $shortUrl = ShortUrl::create($data); // 将ID进行 $uri = dec52($shortUrl->id); $shortUrl->uri = $uri; $shortUrl->save(); $domain = $this->request->domain(); return json(['code' => self::success, 'data' => $domain . '/' . $uri]); } /* * 分享员工上传的案例 */ public function use_talkskill($id) { $token = $this->request->token; $condition = ['id' => $id, 'root_id' => $token['root_org']]; $obj = MaterialCase::where($condition)->find(); if ($obj['from'] == 0) return; //如果是后台上传的直接返回 if ($obj['employee_id'] == $token['employee_id']) return; //如果转发的是自己上传的案例直接返回 Db::startTrans(); try { $end = true; $type = 2; $where = []; $where[] = ['type', '=', $type]; $where[] = ['talkskill_id', '=', $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'] = $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); } else { $end = false; } if ($end) { //未计算积分的被使用次数 $where1[] = ['status', '=', 0]; $where1[] = ['type', '=', $type]; $where1[] = ['talkskill_id', '=', $id]; $where1[] = ['root_id', '=', $token['root_org']]; $credits_log = CreditsLog::where($where1)->select()->toArray(); $count = count($credits_log); if ($count == 0) { $end = false; } } if ($end) { //查询规则 $rule = CreditsSetting::where([['root_id', '=', $token['root_org']], ['code', '=', 'material_case_integral']])->value('value'); $rule = $rule ? json_decode($rule, true) : ['case_num' => 1, 'case_integral' => 2]; $rule = ['person' => $rule['case_num'], 'credits' => $rule['case_integral']]; //计算积分 if ($count >= $rule['person']) { $credits = new Credits(); $save = []; $credits->employee_id = $obj['employee_id']; $credits->root_id = $token['root_org']; $credits->credits = $rule['credits']; $credits->type = 0; $credits->json = 'upcaseid=' . $id; $credits->remark = '上传案例被转发使用'; $credits->save(); $id = $credits->id; $c_where[] = ['employee_id', '=', $obj['employee_id']]; $c_where[] = ['root_id', '=', $token['root_org']]; $c_where[] = ['type', '=', 0]; $sum = Credits::where($c_where)->sum('credits'); Credits::where([['root_id','=',$token['root_org']],['id', '=', $id],['employee_id', '=', $obj['employee_id']]])->update(['sum' => $sum]); CreditsLog::where([['id', 'in', array_column($credits_log, 'id')]])->update(['status' => 1]); } } Db::commit(); } catch (\Exception $e) { // 回滚事务 Db::rollback(); } } private function getTicket() { $ticket = time() . rand(1000, 9999); $find = QrcodeQuery::where('ticket', '=', $ticket)->findOrEmpty(); if (!$find->isEmpty()) { return $this->getTicket(); } return $ticket; } /** * 朋友圈分享二维码 */ public function qrcode() { $param = $this->request->param(); $token = $this->request->token; // 获取小程序二维码 $mini = Miniprogram::where([['root_id', '=', $token['root_org']]])->find(); $qrObj = new Qrcode; if ($param['path'] == 'pages/other/other'){ $qr_query['ticket'] = $this->getTicket(); $qr_query['content'] = $param['query']; QrcodeQuery::create($qr_query); $param['query'] = 'ticket=' . $qr_query['ticket']; } $qrdata = [ 'scene' => $param['query'], 'page' => $param['path'], 'width' => '280px', ]; $qr = $qrObj->getUnlimited($mini->accesstoken, $qrdata); $rs = json_decode($qr, true); if (!is_null($rs)) { trace('名片二维码生成失败' . ';error:' . $qr, 'error'); } $path = 'share_qr_unlimit' . DIRECTORY_SEPARATOR . uniqid() . '.jpeg'; ossContentUpload($path, $qr); return json(['code' => 0, 'data' => 'https://' . config('app.ali_oss_bindurl') . '/' . $path]); } public function getQueryByTicket($ticket){ $query = QrcodeQuery::where('ticket', '=', $ticket)->value('content'); return json(['code'=> 0, 'data'=> $query]); } }