Profile.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <?php
  2. namespace app\api\controller;
  3. use app\model\Company;
  4. use app\model\Customer;
  5. use app\model\CustomerClue;
  6. use app\model\Employee;
  7. use app\model\Footprints;
  8. use app\model\Miniprogram;
  9. use app\model\Org;
  10. use app\model\User;
  11. use app\model\UserCollect;
  12. use app\model\UserSignLog;
  13. use app\model\CustomerSubscribe;
  14. use app\model\Designer;
  15. use app\model\QuoteRecord;
  16. use think\facade\Console;
  17. use app\model\VrView;
  18. use app\model\DesignerCollectionWorks;
  19. use xiaohongwu\Vr;
  20. class Profile extends Base
  21. {
  22. /**
  23. * 签到
  24. */
  25. public function sign()
  26. {
  27. $token = $this->request->token;
  28. $sign = UserSignLog::where([['user_id', '=', $token['uid']], ['date', '=', date('Y-m-d')], ['root_id', '=', $token['root_org']]])->find();
  29. if ($sign) {
  30. return json(['code' => self::error_msg, 'msg' => '签到失败,请勿重复签到']);
  31. }
  32. // 连续签到天数
  33. $day = UserSignLog::where([['user_id', '=', $token['uid']], ['date', '=', date('Y-m-d', strtotime('yesterday'))], ['root_id', '=', $token['root_org']]])->value('day');
  34. $sign = UserSignLog::create([
  35. 'user_id' => $token['uid'],
  36. 'date' => date('Y-m-d'),
  37. 'day' => $day ? $day + 1 : 1,
  38. 'root_id' => $token['root_org']
  39. ]);
  40. //累计勋章
  41. Console::call('medal', ['sign', (string)$token['employee_id'], (string)$token['root_org']]);
  42. return json(['code' => self::success, 'msg' => '签到成功', 'sign' => $sign->day]);
  43. }
  44. /**
  45. * 用户收藏记录
  46. */
  47. public function collect($page, $limit)
  48. {
  49. $data = UserCollect::with(['content'])->where('user_id', $this->request->token['uid'])->order('addtime desc')
  50. // ->page($page,$limit)
  51. ->select()->toArray();
  52. $data = array_filter($data, function ($v) {
  53. if (isset($v['content']['del']) && $v['content']['del'] == 0) {
  54. return true;
  55. } elseif (isset($v['content']['delete_time']) && $v['content']['delete_time'] == 0) {
  56. return true;
  57. } else {
  58. return false;
  59. }
  60. });
  61. $data = array_slice($data, ($page - 1) * $limit, $limit);
  62. return json(['code' => self::success, 'data' => $data]);
  63. }
  64. /*
  65. * 获客线索数量
  66. */
  67. public function getCustomerCount()
  68. {
  69. $conditon = [['employee_id', '=', $this->request->token['employee_id']]];
  70. $total = CustomerClue::where($conditon)->count();
  71. $conditon[] = ['addtime', 'like', date('Y-m-d') . '%'];
  72. $today = CustomerClue::where($conditon)->count();
  73. return json(['code' => 0, 'msg' => '获取成功', 'total' => $total, 'today' => $today]);
  74. }
  75. /**
  76. * 线索列表
  77. */
  78. public function customernew($page, $limit, $state = '', $phone = '')
  79. {
  80. $token = $this->request->token;
  81. $condition[] = ['employee_id', '=', $token['employee_id']];
  82. $state === '' ?: setCondition($state, 'state', '=', $condition);
  83. // setCondition($means, 'means', 'in', $condition);
  84. if ($phone == 'has') $condition[] = ['phone', 'NOTNULL', null];
  85. elseif ($phone == 'hasno') $condition[] = ['phone', 'NULL', null];
  86. $data = CustomerClue::field('id,uid,phone,addtime,updatetime,state')->with(['user'])->withCount(['subscribe' => function ($query) use ($token) {
  87. $query->where('root_id', $token['root_org']);
  88. }, 'footprints'])->where($condition)->order('updatetime desc')->page($page, $limit)->select();
  89. foreach ($data as $k => $v) {
  90. if ($v['nickname'] == '微信用户'){
  91. $data[$k]['nickname'] = '游客';
  92. }
  93. $data[$k]['updatetime'] = $v['updatetime'] ? explode(' ', $v['updatetime']) : explode(' ', $v['addtime']);
  94. if(empty($v['phone'])){
  95. $v['phone'] = QuoteRecord::where(['employee_id'=>$token['employee_id'], 'uid'=>$v['uid']])->value('phone');
  96. }
  97. }
  98. return json(['code' => self::success, 'msg' => '获取成功', 'user' => $data]);
  99. }
  100. //线索详情
  101. public function clue_detail()
  102. {
  103. $token = $this->request->token;
  104. $data = $this->request->only(['id']);
  105. $clue_data = CustomerClue::with(['user'])->where([['id', '=', $data['id']], ['employee_id', '=', $token['employee_id']]])->field('id,uid,phone,addtime,updatetime,state')->find();
  106. if (!empty($clue_data)) {
  107. return json(['code' => 0, 'msg' => '获取成功', 'data' => $clue_data]);
  108. } else {
  109. return json(['code' => 1, 'msg' => '获取失败', 'data' => null]);
  110. }
  111. }
  112. /**
  113. * 客户访问记录(👣)
  114. */
  115. public function footprints($id)
  116. {
  117. $token = $this->request->token;
  118. $clue = CustomerClue::where([['id', '=', $id], ['employee_id', '=', $token['employee_id']]])->find();
  119. if (empty($clue)) return json(['code' => self::success, 'data' => [], 'msg' => '获取成功']);
  120. // 查询条件设置
  121. $condition = [
  122. ['addtime', '>=', $clue->addtime],
  123. ['uid', '=', $clue->uid],
  124. // ['employee_id', '=', $this->request->token['employee_id']],
  125. ['org_id', 'in', orgSubIds($token['root_org'])]
  126. ];
  127. $data = Footprints::where($condition)->field('id,pipe_type,reg_info,visit_due_time,addtime,uid')->order('addtime desc')->select();
  128. if ($data) {
  129. //装修案例预约记录
  130. $w2[] = ['uid', 'in', array_column($data->toArray(), 'uid')];
  131. $w2[] = ['root_id', '=', $token['root_org']];
  132. $sub = CustomerSubscribe::where($w2)->field('sucai_id,uid')->select()->toArray();
  133. foreach ($data as $k => $v) {
  134. $data[$k]['group_view'] = [];
  135. $data[$k]['subscribe'] = 0;
  136. $data[$k]['phone'] = '';
  137. if ($v['pipe_type'] == 'materialCase') {
  138. $data[$k]['subscribe'] = 0;
  139. foreach ($sub as $k2 => $v2) {
  140. $json = json_decode($v->getData('reg_info'), true);
  141. if ($v2['uid'] == $v['uid'] && $v2['sucai_id'] == $json['id']) {
  142. $data[$k]['subscribe'] = 1;
  143. break;
  144. }
  145. }
  146. }elseif(in_array($v['pipe_type'],['groupVr','housetypeVr'])) {
  147. $json = json_decode($v->getData('reg_info'), true);
  148. $group_view = isset($json['view_foots']) ? $json['view_foots'] : [];
  149. if ($group_view) {
  150. $vids = VrView::where([['id','in',array_column($group_view,'vid')]])->column('view_title','id');
  151. foreach ($group_view as $key => $value) {
  152. $group_view[$key]['title'] = isset($vids[$value['vid']]) ? ($vids[$value['vid']] ?: '未命名场景') : '未命名场景';
  153. }
  154. }
  155. $data[$k]['group_view'] = $group_view;
  156. $data[$k]['phone'] = isset($json['phone']) ? $json['phone'] : '';
  157. }
  158. }
  159. }
  160. return json(['code' => self::success, 'data' => $data, 'msg' => '获取成功']);
  161. }
  162. /**
  163. * 线索无效
  164. */
  165. public function invalidClue($id)
  166. {
  167. $clue = CustomerClue::where([['id', '=', $id], ['employee_id', '=', $this->request->token['employee_id']]])->find();
  168. if (empty($clue)) return json(['code' => self::success, 'msg' => '操作失败']);
  169. $clue->state = 2;
  170. $clue->save();
  171. return json(['code' => self::success, 'msg' => '操作成功']);
  172. }
  173. /**
  174. * 更新个人二维码
  175. */
  176. public function qrcode($qr)
  177. {
  178. $data['qrcode'] = $qr;
  179. $data['media_id'] = input('media_id', '');
  180. $data['weixin_media'] = input('weixin_media', '');
  181. Employee::where('id', $this->request->token['employee_id'])->update($data);
  182. return json(['code' => self::success, 'msg' => '修改成功']);
  183. }
  184. /**
  185. * 更新个人头像
  186. */
  187. public function up_headimg()
  188. {
  189. $data['headimg'] = input('headimg', '', 'trim');
  190. if (empty($data['headimg'])) return json(['code' => 1, 'msg' => '图片为空']);
  191. $ali_oss_bindurl = 'https://' . config('app.ali_oss_bindurl') . '/';
  192. $headimgurl = $ali_oss_bindurl . $data['headimg'] . '?x-oss-process=image/resize,w_132';
  193. User::where('id', $this->request->token['uid'])->update(['headimgurl' => $headimgurl]);
  194. return json(['code' => self::success, 'msg' => '修改成功']);
  195. }
  196. /**
  197. * 更新形象照
  198. */
  199. public function image_photo()
  200. {
  201. $image_photo = input('image_photo', '', 'trim');
  202. Employee::where('id', $this->request->token['employee_id'])->save(['image_photo' => $image_photo]);
  203. Designer::where('employee_id', '=', $this->request->token['employee_id'])->save(['headimgurl' => $image_photo]);
  204. return json(['code' => self::success, 'msg' => '修改成功']);
  205. }
  206. /**
  207. * 设置员工个人信息
  208. */
  209. public function edit_employee()
  210. {
  211. $param = $this->request->only(['position', 'wx', 'nickname', 'name']);
  212. $find = Employee::find($this->request->token['employee_id']);
  213. $find->user->nickname = $param['nickname'];
  214. $find->position = $param['position'];
  215. $find->wx = $param['wx'];
  216. if($param['name']) $param['initials'] = strtoupper(substr(hanzi2pinyin($param['name']),0,1));
  217. $find->name = $param['name'];
  218. $find->user->save();
  219. $result = $find->save();
  220. if ($result) {
  221. return json(['code' => self::success, 'msg' => '修改成功']);
  222. } else {
  223. return json(['code' => self::error_msg, 'msg' => '修改失败']);
  224. }
  225. }
  226. /**
  227. * 获取加入的企业
  228. */
  229. public function company()
  230. {
  231. $token = $this->request->token;
  232. $mini_setting = appletConfiguration();
  233. // 用token中的openid获取用户的uid列表
  234. $uidList = User::where([$mini_setting['mini_openid'] => $token['openid']])->whereOr([$mini_setting['unionid'] => $token['unionid']])->column('id');
  235. $employees = Employee::where([['uid', 'in', $uidList], ['state', '=', '在职'], ['disable', '=', 0]])->column('root_id, is_manager, org_id', 'root_id');
  236. $orgs = Org::where([['id', 'in', array_column($employees, 'org_id')]])->column('id,name', 'id');
  237. $notifyList = Miniprogram::where([['root_id', 'in', array_column($employees, 'root_id')]])->column('root_id,notify', 'root_id');
  238. //2023-03-21店面可以在不同的小程序中使用 去掉条件, ['mini', '=', $token['mini']]
  239. $companyList = Company::with(['brand'])->where([['root_id', 'in', array_column($employees, 'root_id')]])->select()->visible(['company_name', 'root_id', 'status', 'end_date','logo'])->toArray();
  240. foreach ($companyList as &$item) {
  241. $item['client_type'] = isset($notifyList[$item['root_id']]) ? $notifyList[$item['root_id']]['notify'] : '';
  242. $item['is_manager'] = isset($employees[$item['root_id']]) ? $employees[$item['root_id']]['is_manager'] : 0;
  243. $item['org_name'] = (isset($employees[$item['root_id']]) && isset($orgs[$employees[$item['root_id']]['org_id']])) ? $orgs[$employees[$item['root_id']]['org_id']]['name'] : '';
  244. if ($item['status'] == 1) {
  245. $item['off'] = 1;
  246. $item['off_remark'] = '账号被禁用';
  247. } elseif ($item['end_date'] < date('Y-m-d')) {
  248. $item['off'] = 1;
  249. $item['off_remark'] = '账号已过期';
  250. } else {
  251. $item['off'] = 0;
  252. $item['off_remark'] = '账号正常';
  253. }
  254. if(!empty($item['logo']) && !empty($item['brand'])){
  255. $item['brand']['logo']=$item['logo'];
  256. }
  257. }
  258. return json(['code' => 0, 'data' => $companyList]);
  259. }
  260. /**
  261. * 设计师增加个人作品
  262. */
  263. public function designer_add_works()
  264. {
  265. $param = $this->request->only(['id'=>0,'title', 'style_id'=>0,'housetype_id'=>0, 'square', 'money','type','desc'=>'','vr_case'=>'']);
  266. $token = $this->request->token;
  267. if (strlen($param['title']) > 50) {
  268. return json(['code' => self::error_msg, 'msg' => '作品名称过长']);
  269. }
  270. $cover_img = $vrstr = null;
  271. if (!empty($param['vr_case']) && $param['type'] == 2){
  272. $builmod = new Building($this->app);
  273. $vrlist = explode(',',$param['vr_case']);
  274. foreach($vrlist as $val){
  275. $vrstr.= $builmod->vrlink_set($val).',';
  276. }
  277. $vrstr = trim($vrstr,',');
  278. }
  279. if (!empty($param['desc']) && $param['type'] == 1){
  280. $imgs = explode(',',$param['desc']);
  281. $cover_img = $imgs[0];
  282. }
  283. $add = [
  284. 'title' => $param['title'],
  285. 'housetype_id' => $param['housetype_id'],
  286. 'square' => $param['square'],
  287. 'money' => $param['money'],
  288. 'type' => $param['type'],
  289. 'desc' => $param['desc'],
  290. 'cover_img'=> $cover_img,
  291. 'vr_case' => $vrstr,
  292. 'style_id' =>$param['style_id']
  293. ];
  294. if($param['id']){
  295. $check = DesignerCollectionWorks::where([['root_id','=',$token['root_org']],['employee_id','=',$token['employee_id']],['id','=',$param['id']]])->find();
  296. if(empty($check)) return json(['code'=>1,'msg'=>'数据不存在']);
  297. $add['id'] = $param['id'];
  298. DesignerCollectionWorks::update($add);
  299. }else{
  300. $add['employee_id'] = $token['employee_id'];
  301. $add['root_id'] = $token['root_org'];
  302. $add['designer_id'] = $token['org_type'] == 2 ? $token['employee_id'] : 0;
  303. $ms = DesignerCollectionWorks::create($add);
  304. }
  305. return json(['code'=>0,'msg'=>'编辑成功']);
  306. }
  307. /**
  308. * 设计师个人作品详情
  309. */
  310. public function designer_worksdet()
  311. {
  312. $param = $this->request->only(['id']);
  313. $token = $this->request->token;
  314. $data = DesignerCollectionWorks::with(['decostyle','housetype'])->where([['root_id','=',$token['root_org']],['employee_id','=',$token['employee_id']],['id','=',$param['id']]])->find();
  315. if(empty($data)) return json(['code'=>1,'msg'=>'数据不存在']);
  316. return json(['code'=>0,'data'=>$data,'msg'=>'获取成功']);
  317. }
  318. /**
  319. * 设计师作品集列表
  320. */
  321. public function designer_worklist()
  322. {
  323. $param = $this->request->only(['page'=>1,'limit'=>10]);
  324. $token = $this->request->token;
  325. $list = DesignerCollectionWorks::with(['decostyle','housetype'])->where([['root_id','=',$token['root_org']],['employee_id','=',$token['employee_id']]])->page($param['page'],$param['limit'])->select()->toArray();
  326. foreach($list as $key=>$val){
  327. if($val['type'] == 2 && !empty($val['vr_case'])){
  328. $list[$key]['cover_img'] = !empty($val['vr_case'][0]['vr_img']) ? $val['vr_case'][0]['vr_img'] : '';
  329. }
  330. }
  331. return json(['code'=>0,'data'=>$list,'msg'=>'获取成功']);
  332. }
  333. }