UsersServer - 副本.php 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989
  1. <?php
  2. namespace app\admin\server\user;
  3. use app\admin\model\Package;
  4. use app\admin\model\UserAuth;
  5. use app\admin\model\UserBasicHealthData;
  6. use app\admin\model\UserBasicHealthDataLog;
  7. use app\admin\model\UserDoctorsLog;
  8. use app\admin\model\UserMedicalExaminationReport;
  9. use app\admin\model\User;
  10. use app\admin\model\IntelligenceLog;
  11. use app\admin\model\IntelligenceEquipment;
  12. use app\admin\model\UserPackageLog;
  13. use app\admin\server\package\PackageServer;
  14. use app\admin\model\UserRelatives;
  15. use app\admin\model\UserProperty;
  16. /**
  17. * 会员服务层
  18. * Class UsersServer
  19. * @package app\admin\server\user
  20. */
  21. class UsersServer
  22. {
  23. /**
  24. * Notes:会员信息
  25. * @param int $user_id
  26. * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null
  27. * User: yym
  28. * Date: 2022/7/26
  29. */
  30. public static function getUserInfo(int $user_id)
  31. {
  32. $info = User::getUserInfo($user_id);
  33. if(empty($info))
  34. {
  35. throw new \Exception('查无此会员信息');
  36. }
  37. $info['user_category'] = User::USER_CATEGORY[$info['user_type']] ?? '';
  38. $info['user_create_time'] = date("Y-m-d H:i:s", $info['user_create_time']);
  39. $info['member_is_owner'] = User::USER_OWNER[$info['user_is_owner']] ?? '';
  40. $auth_status = '';
  41. $auth_status_msg = '';
  42. if(empty($info['member_auth_list']))
  43. {
  44. $auth_status = '未认证';
  45. $auth_status_msg = '实名认证';
  46. }elseif((count($info['member_auth_list']) == 1 || count($info['member_auth_list']) == 2) && !empty($info['member_auth'])){
  47. $auth_status = UserAuth::MEMBER_AUTH_STATUS[$info['member_auth']['auth_status']];
  48. $auth_status_msg = '会员升级';
  49. }elseif((count($info['member_auth_list']) == 1 || count($info['member_auth_list']) == 2) && empty($info['member_auth'])){
  50. $auth_status = '认证通过';
  51. $auth_status_msg = '会员升级';
  52. }
  53. $info['auth_status'] = $auth_status;
  54. $info['auth_status_msg'] = $auth_status_msg;
  55. if(!empty($info['member_auth_list']))
  56. {
  57. foreach ($info['member_auth_list'] as $k => $item)
  58. {
  59. if($item['auth_type'] == '0')
  60. {
  61. $info['member_auth_list'][$k]['auth_content'] = json_decode($item['auth_content'], true);
  62. }
  63. }
  64. }
  65. unset($info['member_certinfo']);
  66. return $info;
  67. }
  68. /**
  69. * Notes:会员列表
  70. * @param string $keywords
  71. * @param int $category
  72. * @param int $status
  73. * @param int $page
  74. * @param int $limit
  75. * @return array
  76. * User: yym
  77. * Date: 2022/8/4
  78. */
  79. public static function getUserList(string $keywords, int $category, int $status, int $page, int $limit)
  80. {
  81. [$list, $count] = User::getUserList($keywords, $category, $status, $page, $limit);
  82. if(!empty($list))
  83. {
  84. foreach ($list as &$row)
  85. {
  86. $row['user_category'] = User::USER_CATEGORY[$row['user_type']] ?? '';
  87. $row['user_create_time']= date("Y-m-d H:i:s", $row['user_create_time']);
  88. $row['member_is_owner'] = User::USER_OWNER[$row['user_is_owner']] ?? '';
  89. $row['sonnum'] = User::where('user_spread_uid',$row['user_id'])->count();
  90. $row['rejectMsg'] = '';
  91. $auth_status = '';
  92. $auth_status_msg = '';
  93. $auth_status_type = '';
  94. if(empty($row['member_auth_list']))
  95. {
  96. $auth_status = '未认证';
  97. $auth_status_msg = '实名认证';
  98. $auth_status_type = '未认证';
  99. }elseif (count($row['member_auth_list']) == 1 && empty($row['member_auth'])){
  100. $auth_status = '已实名认证';
  101. $auth_status_msg = '实名认证';
  102. $auth_status_type = '未购买';
  103. $row['rejectMsg'] = $row['member_auth_list'][0]['auth_content'];
  104. }elseif (count($row['member_auth_list']) == 1 && !empty($row['member_auth'])){
  105. $auth_status = '已提交认证';
  106. $auth_status_msg = '实名认证';
  107. $auth_status_type = UserAuth::MEMBER_AUTH_STATUS[$row['member_auth']['auth_status']];
  108. $row['rejectMsg'] = $row['member_auth_list'][0]['auth_content'];
  109. }elseif (count($row['member_auth_list']) == 2 && empty($row['member_auth'])){
  110. $auth_status = '已升级认证';
  111. $auth_status_msg = '会员升级';
  112. $auth_status_type = '已购买';
  113. $row['rejectMsg'] = $row['member_auth_list'][1]['auth_content'];
  114. }elseif (count($row['member_auth_list']) == 2 && !empty($row['member_auth'])){
  115. $auth_status = '已提交认证';
  116. $auth_status_msg = '会员升级';
  117. $auth_status_type = '已购买';
  118. $row['rejectMsg'] = $row['member_auth_list'][1]['auth_content'];
  119. }
  120. $row['auth_status'] = $auth_status;
  121. $row['auth_status_msg'] = $auth_status_msg;
  122. $row['auth_status_type'] = $auth_status_type;
  123. if(!empty($row['member_auth_list']))
  124. {
  125. foreach ($row['member_auth_list'] as $k => $item)
  126. {
  127. if($item['auth_type'] == '0')
  128. {
  129. $row['member_auth_list'][$k]['auth_content'] = json_decode($item['auth_content'], true);
  130. }
  131. }
  132. }
  133. unset($row['member_certinfo']);
  134. }
  135. unset($row);
  136. }
  137. return compact('list', 'count');
  138. }
  139. /**
  140. * Notes: 添加设备
  141. * @return int
  142. * User: ZQ
  143. * Date: 2022/11/14
  144. */
  145. public static function userInsert($user_account,$user_login_pwd,$user_again_pwd,$user_nickname,$user_headimgurl,$user_sex,$user_birthday,$user_age,$user_register_address,$user_phone,$user_status,$user_real_name,$user_card_id,$user_certinfo,$user_is_owner,$user_type,$user_spread_uid,$user_source,$admin_id,$user_register_type)
  146. {
  147. User::affairBegin();
  148. try {
  149. $data = [];
  150. //判断账号是否唯一
  151. $account = User::getUserAccount($user_account);
  152. if (!empty($account)){
  153. throw new \Exception('会员账号已存在!');
  154. }
  155. //判断身份证是否唯一
  156. if (!empty($user_card_id)){
  157. $card = User::getUserCard($user_card_id);
  158. if (!empty($card)){
  159. throw new \Exception('会员身份证已存在!');
  160. }
  161. }
  162. $data['user_account'] = $user_account;
  163. if ($user_login_pwd == $user_again_pwd){
  164. $data['user_login_pwd'] = md5(sha1($user_login_pwd));
  165. }else{
  166. throw new \Exception('两次密码不一致!');
  167. }
  168. $data['user_nickname'] = $user_nickname;
  169. $data['user_headimgurl'] = $user_headimgurl;
  170. $data['user_sex'] = $user_sex;
  171. $data['user_birthday'] = $user_birthday;
  172. $data['user_age'] = $user_age;
  173. $data['user_register_address'] = $user_register_address;
  174. $data['user_phone'] = $user_phone;
  175. $data['user_package_status'] = 0;
  176. $data['user_package_id'] = 0;
  177. $data['user_status'] = $user_status;
  178. $data['user_real_name'] = $user_real_name;
  179. $data['user_card_id'] = $user_card_id;
  180. $data['user_certinfo'] = $user_certinfo ? implode(',',$user_certinfo) : '';
  181. $data['user_is_owner'] = $user_is_owner;
  182. $data['user_type'] = $user_type;
  183. $data['user_register_type'] = $user_register_type;
  184. if ($user_type == 2){
  185. throw new \Exception('会员身份选择错误!');
  186. }
  187. $data['user_spread_uid'] = $user_spread_uid;
  188. $data['user_spread_time'] = $user_spread_uid ? time() : '';
  189. $data['user_source'] = $user_source;
  190. $data['user_create_time'] = time();
  191. $result = User::insertGetId($data);
  192. if ($user_type == 1){
  193. $auth = [];
  194. $auth['auth_user_id'] = $result;
  195. $auth['auth_type'] = 0;
  196. $auth['auth_content'] = json_encode(['card_front'=>$user_certinfo[0],'card_side'=>$user_certinfo[1]]);
  197. $auth['auth_status'] = 1;
  198. $auth['auth_status_info'] = '添加新会员实名认证审核';
  199. $auth['auth_admin_id'] = $admin_id;
  200. $auth['auth_examine_time'] = time();
  201. $auth['auth_create_time'] = time();
  202. $mation = UserAuth::insertGetId($auth);
  203. if (empty($mation)){
  204. User::affairRollback();
  205. throw new \Exception('添加失败!');
  206. }
  207. }
  208. if (!empty($result)){
  209. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '添加会员-编号: ' . $result;
  210. plog('user-equipment-create', '公共-会员-添加会员', $msg);
  211. User::affairCommit();
  212. return $result;
  213. }
  214. throw new \Exception('添加失败!');
  215. }catch (\Exception $exception){
  216. User::affairRollback();
  217. throw new \Exception($exception->getMessage(), 500);
  218. }
  219. }
  220. /**
  221. * Notes:会员审核操作
  222. * @param int $admin_id
  223. * @param int $user_id
  224. * @param string $status
  225. * @param string $content
  226. * @param string $category
  227. * @return bool
  228. * @throws \Exception
  229. * User: yym
  230. * Date: 2022/8/4
  231. */
  232. public static function authUser(int $admin_id, int $user_id, string $status, string $content, string $category)
  233. {
  234. User::affairBegin();
  235. try {
  236. if($status == UserAuth::RETURN && empty($content))
  237. {
  238. throw new \Exception('审核驳回,驳回理由不能为空!');
  239. }
  240. $update = array(
  241. 'auth_status' => $status,
  242. 'auth_status_info' => $content,
  243. 'auth_admin_id' => $admin_id,
  244. 'auth_examine_time' => time()
  245. );
  246. $result1 = true;
  247. $auth_type = 0;
  248. //审核通过 更新会员等级
  249. if($status == UserAuth::DONE && $category == '实名认证')
  250. {
  251. $auth_type = 0;
  252. $result1 = User::updateMember($user_id, ['user_type' => User::ORDINARY, 'user_real_status' => User::REAL_YES]);
  253. events('createUserNews', ['log_type' => 0, 'log_uid' => $user_id, 'log_content' => '您的'.$category.'审核成功了!']);
  254. }
  255. //审核通过 更新会员等级
  256. if($status == UserAuth::DONE && $category == '会员升级')
  257. {
  258. $auth_type = 1;
  259. $result1 = User::updateMember($user_id, ['user_type' => User::FORMAL, 'user_package_status' => User::PACKAGE_YES]);
  260. events('createUserNews', ['log_type' => 0, 'log_uid' => $user_id, 'log_content' => '您的'.$category.'审核成功了!']);
  261. }
  262. $result = UserAuth::updateAuth($user_id, $auth_type, $update);
  263. plog('user.auth', '会员-身份-审核', '管理员审核会员:' . $user_id . '审核意见内容:' . $content);
  264. if($result && $result1)
  265. {
  266. User::affairCommit();
  267. return true;
  268. }
  269. throw new \Exception('审核失败!');
  270. }catch (\Exception $exception){
  271. User::affairRollback();
  272. throw new \Exception($exception->getMessage(), 500);
  273. }
  274. }
  275. /**
  276. * Notes:获取会员体检信息
  277. * @param int $user_id
  278. * @return array
  279. * @throws \Exception
  280. * User: yym
  281. * Date: 2022/9/21
  282. */
  283. public static function getUserReport(int $user_id)
  284. {
  285. try {
  286. $info = User::getMemberInfo($user_id);
  287. if(empty($info))
  288. {
  289. throw new \Exception('会员信息不存在');
  290. }
  291. if(empty($info['user_card_id']))
  292. {
  293. throw new \Exception('暂无会员身份证信息');
  294. }
  295. //获取体检信息
  296. [$list, $count] = UserMedicalExaminationReport::getList($user_id);
  297. if(!empty($list))
  298. {
  299. foreach ($list as $k => $item)
  300. {
  301. $list[$k]['report_content'] = json_decode($item['report_content'], true);
  302. $list[$k]['report_add_time'] = date("Y-m-d H:i:s", $item['report_add_time']);
  303. }
  304. }
  305. return compact('list', 'count');
  306. }catch (\Exception $exception){
  307. throw new \Exception($exception->getMessage(), 500);
  308. }
  309. }
  310. /**
  311. * Notes:获取会员设备列表
  312. * @param int $equipment_user_id
  313. * @param string $equipment_name
  314. * @return array
  315. * @throws \Exception
  316. * User: ZQ
  317. * Date: 2022/9/23
  318. */
  319. public static function getUserEquipment(int $page,int $limit, $equipment_user_id, string $equipment_name, $equipment_class)
  320. {
  321. try {
  322. [$list,$count] = IntelligenceEquipment::equipmentList($page, $limit, $equipment_user_id, $equipment_name, $equipment_class);
  323. if(!empty($list))
  324. {
  325. foreach ($list as $k => $item)
  326. {
  327. if (empty($item['user_nickname'])){
  328. $list[$k]['username'] = $item['user_account'];
  329. }else{
  330. $list[$k]['username'] = $item['user_nickname'];
  331. }
  332. $list[$k]['equipment_create_time'] = date("Y-m-d H:i:s", $item['equipment_create_time']);
  333. if (!empty($item['equipment_update_time'])){
  334. $list[$k]['equipment_update_time'] = date("Y-m-d H:i:s", $item['equipment_update_time']);
  335. }
  336. if (!empty($item['equipment_up_end_time'])){
  337. $list[$k]['equipment_up_end_time'] = date("Y-m-d H:i:s", $item['equipment_up_end_time']);
  338. }
  339. if (!empty($item['equipment_down_end_time'])){
  340. $list[$k]['equipment_down_end_time'] = date("Y-m-d H:i:s", $item['equipment_down_end_time']);
  341. }
  342. }
  343. }
  344. return compact('list', 'count','page','limit');
  345. }catch (\Exception $exception){
  346. throw new \Exception($exception->getMessage(), 500);
  347. }
  348. }
  349. /**
  350. * Notes:获取会员设备详情
  351. * @param int $equipment_id
  352. * @return array
  353. * @throws \Exception
  354. * User: ZQ
  355. * Date: 2022/9/23
  356. */
  357. public static function userEquipmentInfo($equipment_id)
  358. {
  359. try {
  360. $where = [];
  361. $where['equipment_id'] = $equipment_id;
  362. $where['equipment_del'] = 0;
  363. $data = IntelligenceEquipment::equipmentInfor($where);
  364. if(!empty($data))
  365. {
  366. if (empty($data['user_nickname'])){
  367. $data['username'] = $data['user_account'];
  368. }else{
  369. $data['username'] = $data['user_nickname'];
  370. }
  371. $data['equipment_create_time'] = date("Y-m-d H:i:s", $data['equipment_create_time']);
  372. if (!empty($data['equipment_update_time'])){
  373. $data['equipment_update_time'] = date("Y-m-d H:i:s", $data['equipment_update_time']);
  374. }
  375. if (!empty($data['equipment_up_end_time'])){
  376. $data['equipment_up_end_time'] = date("Y-m-d H:i:s", $data['equipment_up_end_time']);
  377. }
  378. if (!empty($data['equipment_down_end_time'])){
  379. $data['equipment_down_end_time'] = date("Y-m-d H:i:s", $data['equipment_down_end_time']);
  380. }
  381. }
  382. return $data;
  383. }catch (\Exception $exception){
  384. throw new \Exception($exception->getMessage(), 500);
  385. }
  386. }
  387. /**
  388. * Notes:获取设备消息列表
  389. * @param int $log_user_id
  390. * @param int $log_equipment_id
  391. * @return array
  392. * @throws \Exception
  393. * User: ZQ
  394. * Date: 2022/9/23
  395. */
  396. public static function getEquipmentLog(int $page,int $limit, $log_user_id, $log_equipment_id)
  397. {
  398. try {
  399. [$list,$count] = IntelligenceLog::equipmentLogList($page, $limit, $log_user_id, $log_equipment_id);
  400. if(!empty($list))
  401. {
  402. foreach ($list as $k => $item)
  403. {
  404. $log_content = json_decode($item['log_content'],true);
  405. $content = [];
  406. $content[0]['产品id'] = $log_content['productId'] ? $log_content['productId'] : '' ;
  407. $content[1]['消息类型'] = $log_content['messageType'] ? $log_content['messageType'] : '';
  408. $content[2]['IMEI'] = $log_content['IMEI'] ? $log_content['IMEI'] : '';
  409. $content[3]['产品类型'] = $log_content['payload']['serviceData']['devicetype'] ? $log_content['payload']['serviceData']['devicetype'] : '';
  410. $content[4]['设备id'] = $log_content['deviceId'] ? $log_content['deviceId'] : '';
  411. $list[$k]['log_content'] = $content;
  412. $list[$k]['log_create_time'] = date("Y-m-d H:i:s", $item['log_create_time']);
  413. if (!empty($item['log_update_time'])){
  414. $list[$k]['log_update_time'] = date("Y-m-d H:i:s", $item['log_update_time']);
  415. }
  416. }
  417. }
  418. return compact('list', 'count','page','limit');
  419. }catch (\Exception $exception){
  420. throw new \Exception($exception->getMessage(), 500);
  421. }
  422. }
  423. /**
  424. * Notes:获取会员设备详情
  425. * @param int $log_id
  426. * @return array
  427. * @throws \Exception
  428. * User: ZQ
  429. * Date: 2022/9/23
  430. */
  431. public static function equipmentLogInfo($log_id)
  432. {
  433. try {
  434. $where = [];
  435. $where['log_id'] = $log_id;
  436. $data = IntelligenceLog::logInfor($where);
  437. if(!empty($data))
  438. {
  439. $log_content = json_decode($data['log_content'],true);
  440. $content = [];
  441. $content[0]['产品id'] = $log_content['productId'] ? $log_content['productId'] : '' ;
  442. $content[1]['消息类型'] = $log_content['messageType'] ? $log_content['messageType'] : '';
  443. $content[2]['IMEI'] = $log_content['IMEI'] ? $log_content['IMEI'] : '';
  444. $content[3]['产品类型'] = $log_content['payload']['serviceData']['devicetype'] ? $log_content['payload']['serviceData']['devicetype'] : '';
  445. $content[4]['设备id'] = $log_content['deviceId'] ? $log_content['deviceId'] : '';
  446. $data['log_content'] = $content;
  447. $data['log_create_time'] = date("Y-m-d H:i:s", $data['log_create_time']);
  448. if (!empty($data['log_update_time'])){
  449. $data['log_update_time'] = date("Y-m-d H:i:s", $data['log_update_time']);
  450. }
  451. }
  452. return $data;
  453. }catch (\Exception $exception){
  454. throw new \Exception($exception->getMessage(), 500);
  455. }
  456. }
  457. /**
  458. * Notes:赠送权益包
  459. * @param $user_id
  460. * @param $package_id
  461. * @param $type
  462. * @param $admin_id
  463. * @return bool
  464. * @throws \Exception
  465. * User: yym
  466. * Date: 2022/11/21
  467. */
  468. public static function givePackage($user_id, $package_id, $type, $admin_id)
  469. {
  470. UserPackageLog::affairBegin();
  471. try {
  472. //检测会员是否已赠送或购买此套餐包
  473. $info = UserPackageLog::getInfo($package_id, $user_id);
  474. if(!empty($info))
  475. {
  476. throw new \Exception('会员该套餐包已存在,无法继续赠送');
  477. }
  478. //生成订单记录
  479. $order_id = PackageServer::givePackage($user_id, $package_id);
  480. if(empty($order_id))
  481. {
  482. throw new \Exception('赠送失败!');
  483. }
  484. //生成套餐包记录
  485. $package_info = Package::getInfo($package_id);
  486. if(empty($package_info))
  487. {
  488. throw new \Exception('套餐包不存在!');
  489. }
  490. foreach ($package_info['goods'] as $item)
  491. {
  492. $insert = array(
  493. 'log_user_id' => $user_id,
  494. 'log_package_id' => $package_id,
  495. 'log_package_goods_id' => $item['goods_id'],
  496. 'log_package_status' => UserPackageLog::NORMAL,
  497. 'log_server_number' => $item['goods_num'],
  498. 'log_server_type' => $item['goods_num_type'],
  499. 'log_server_unit' => $item['goods_num_unit'],
  500. 'log_type' => $type,
  501. 'log_add_time' => time(),
  502. 'log_update_time' => time()
  503. );
  504. UserPackageLog::insertData($insert);
  505. }
  506. User::updateMember($user_id, ['user_package_status' => User::PACKAGE_YES, 'user_package_id' => $package_id, 'user_type' => User::FORMAL]);
  507. UserPackageLog::affairCommit();
  508. plog('user.give.package', '会员-赠送-权益包', '管理员:' . $admin_id . '赠送会员:' . $user_id . '权益包:' . $package_id);
  509. return true;
  510. }catch (\Exception $exception){
  511. UserPackageLog::affairRollback();
  512. throw new \Exception($exception->getMessage(), 500);
  513. }
  514. }
  515. /**
  516. * Notes:获取会员下亲属关系列表
  517. * @param int $log_id
  518. * @return array
  519. * @throws \Exception
  520. * User: ZQ
  521. * Date: 2022/11/15
  522. */
  523. public static function relativesList($relatives_user_id)
  524. {
  525. try {
  526. $where = [];
  527. $where['relatives_user_id'] = $relatives_user_id;
  528. $where['relatives_del'] = 0;
  529. $list = UserRelatives::select(['user_relatives.*','user.user_real_name'])
  530. ->where($where)
  531. ->leftJoin('user','user_id','=','user_relatives.relatives_user_id')
  532. ->orderBy('relatives_add_time','DESC')
  533. ->get()->toArray();
  534. if(!empty($list))
  535. {
  536. foreach ($list as $k => $item)
  537. {
  538. $list[$k]['relatives_add_time'] = date("Y-m-d H:i:s", $item['relatives_add_time']);
  539. if (!empty($item['relatives_update_time'])){
  540. $list[$k]['relatives_update_time'] = date("Y-m-d H:i:s", $item['relatives_update_time']);
  541. }
  542. }
  543. }
  544. return $list;
  545. }catch (\Exception $exception){
  546. throw new \Exception($exception->getMessage(), 500);
  547. }
  548. }
  549. /**
  550. * Notes:获取会员亲属关系列表
  551. * @param int $log_id
  552. * @return array
  553. * @throws \Exception
  554. * User: ZQ
  555. * Date: 2022/11/11
  556. */
  557. public static function relativesToList($page,$limit,$keywords)
  558. {
  559. try {
  560. [$list,$count] = UserRelatives::getrelativesList($page,$limit,$keywords);
  561. if(!empty($list))
  562. {
  563. foreach ($list as $k => $item)
  564. {
  565. $list[$k]['relatives_add_time'] = date("Y-m-d H:i:s", $item['relatives_add_time']);
  566. if (!empty($item['relatives_update_time'])){
  567. $list[$k]['relatives_update_time'] = date("Y-m-d H:i:s", $item['relatives_update_time']);
  568. }
  569. }
  570. }
  571. return compact('list', 'page', 'limit', 'count');
  572. }catch (\Exception $exception){
  573. throw new \Exception($exception->getMessage(), 500);
  574. }
  575. }
  576. /**
  577. * Notes:删除会员亲属关系
  578. * @param int $category_id
  579. * @return int
  580. * User: ZQ
  581. * Date: 2022/9/3
  582. */
  583. public static function relativesDel($relatives_id,$admin_id)
  584. {
  585. UserRelatives::affairBegin();
  586. try {
  587. $where = [];
  588. $where['relatives_id'] = $relatives_id;
  589. $data['relatives_del'] = 1;
  590. $result = UserRelatives::where($where)->update($data);
  591. if (!empty($result)){
  592. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '删除会员亲属关系-编号: ' . $relatives_id;
  593. plog('user-relatives-del', '会员-亲属关系-删除亲属关系', $msg);
  594. UserRelatives::affairCommit();
  595. return true;
  596. }
  597. throw new \Exception('删除失败!');
  598. }catch (\Exception $exception){
  599. UserRelatives::affairRollback();
  600. throw new \Exception($exception->getMessage(), 500);
  601. }
  602. }
  603. /**
  604. * Notes:获取会员下亲属关系列表
  605. * @param int $log_id
  606. * @return array
  607. * @throws \Exception
  608. * User: ZQ
  609. * Date: 2022/11/15
  610. */
  611. public static function equipmentList($equipment_user_id)
  612. {
  613. try {
  614. $where = [];
  615. $where['equipment_user_id'] = $equipment_user_id;
  616. $where['equipment_del'] = 0;
  617. $list = IntelligenceEquipment::select(['user_intelligence_equipment.*','intelligence_products.product_name'])
  618. ->where($where)
  619. ->leftJoin('intelligence_products','product_id','=','user_intelligence_equipment.equipment_intelligence_id')
  620. ->orderBy('equipment_create_time','DESC')
  621. ->get()->toArray();
  622. if(!empty($list))
  623. {
  624. foreach ($list as $k => $item)
  625. {
  626. $list[$k]['equipment_create_time'] = date("Y-m-d H:i:s", $item['equipment_create_time']);
  627. $list[$k]['equipment_up_end_time'] = $list[$k]['equipment_up_end_time'] ? date("Y-m-d H:i:s", $item['equipment_up_end_time']) : '';
  628. $list[$k]['equipment_down_end_time'] = $list[$k]['equipment_down_end_time'] ? date("Y-m-d H:i:s", $item['equipment_down_end_time']) : '';
  629. $list[$k]['equipment_update_time'] = $list[$k]['equipment_update_time'] ? date("Y-m-d H:i:s", $item['equipment_update_time']) : '';
  630. }
  631. }
  632. return $list;
  633. }catch (\Exception $exception){
  634. throw new \Exception($exception->getMessage(), 500);
  635. }
  636. }
  637. /**
  638. * Notes: 添加设备
  639. * @return int
  640. * User: ZQ
  641. * Date: 2022/11/14
  642. */
  643. public static function insertEquipment($admin_id, $equipment_intelligence_id, $equipment_user_id, $equipment_name, $equipment_only,$equipment_type,$equipment_class,$equipment_tripartite_sn,$equipment_status,$equipment_property_id)
  644. {
  645. IntelligenceEquipment::affairBegin();
  646. try {
  647. $data = [];
  648. $data['equipment_intelligence_id'] = $equipment_intelligence_id;
  649. $data['equipment_user_id'] = $equipment_user_id;
  650. $data['equipment_name'] = $equipment_name;
  651. $data['equipment_only'] = $equipment_only;
  652. $data['equipment_type'] = $equipment_type;
  653. $data['equipment_class'] = $equipment_class;
  654. $data['equipment_tripartite_sn'] = $equipment_tripartite_sn;
  655. $data['equipment_status'] = $equipment_status;
  656. $data['equipment_property_id'] = $equipment_property_id;
  657. $data['equipment_create_time'] = time();
  658. $result = IntelligenceEquipment::insertGetId($data);
  659. if (!empty($result)){
  660. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '添加会员智能设备-编号: ' . $result;
  661. plog('user-equipment-create', '会员-智能设备-添加智能设备', $msg);
  662. IntelligenceEquipment::affairCommit();
  663. return $result;
  664. }
  665. throw new \Exception('操作失败!');
  666. }catch (\Exception $exception){
  667. IntelligenceEquipment::affairRollback();
  668. throw new \Exception($exception->getMessage(), 500);
  669. }
  670. }
  671. /**
  672. * Notes:查询会员设备唯一编码
  673. * @param int $category_id
  674. * @return int
  675. * User: ZQ
  676. * Date: 2022/11/15
  677. */
  678. public static function equipmentCheck($equipment_only)
  679. {
  680. try {
  681. $where = [];
  682. $where['equipment_only'] = $equipment_only;
  683. $result = IntelligenceEquipment::where($where)->first();
  684. if (!empty($result)){
  685. return $result;
  686. }else{
  687. return false;
  688. }
  689. throw new \Exception('查询失败!');
  690. }catch (\Exception $exception){
  691. throw new \Exception($exception->getMessage(), 500);
  692. }
  693. }
  694. /**
  695. * Notes:删除会员亲属关系
  696. * @param int $category_id
  697. * @return int
  698. * User: ZQ
  699. * Date: 2022/11/15
  700. */
  701. public static function equipmentDel($equipment_id,$admin_id)
  702. {
  703. IntelligenceEquipment::affairBegin();
  704. try {
  705. $where = [];
  706. $where['equipment_id'] = $equipment_id;
  707. $data['equipment_del'] = 1;
  708. $result = IntelligenceEquipment::where($where)->update($data);
  709. if (!empty($result)){
  710. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '删除会员智能产品设备-编号: ' . $equipment_id;
  711. plog('user-relatives-del', '会员-智能产品设备-删除智能产品设备', $msg);
  712. IntelligenceEquipment::affairCommit();
  713. return true;
  714. }
  715. throw new \Exception('删除失败!');
  716. }catch (\Exception $exception){
  717. IntelligenceEquipment::affairRollback();
  718. throw new \Exception($exception->getMessage(), 500);
  719. }
  720. }
  721. /**
  722. * Notes:获取会员固定资产列表
  723. * @param int $property_user_id
  724. * @return array
  725. * @throws \Exception
  726. * User: ZQ
  727. * Date: 2022/11/23
  728. */
  729. public static function propertyList($property_user_id)
  730. {
  731. try {
  732. $where = [];
  733. $where['property_del'] = 0;
  734. $where['property_status'] = 0;
  735. $where['property_user_id'] = $property_user_id;
  736. $list = UserProperty::where($where)->select()->get()->toArray();
  737. return $list;
  738. }catch (\Exception $exception){
  739. throw new \Exception($exception->getMessage(), 500);
  740. }
  741. }
  742. /**
  743. * Notes:添加医生医嘱
  744. * @param int $log_user_id
  745. * @return array
  746. * @throws \Exception
  747. * User: ZQ
  748. * Date: 2022/12/8
  749. */
  750. public static function doctorInsert($log_user_id, $log_type, $log_doctor_id, $log_subject_id, $log_message, $log_resolvent, $admin_id)
  751. {
  752. UserDoctorsLog::affairBegin();
  753. try {
  754. $data = [];
  755. $data['log_user_id'] = $log_user_id;
  756. $data['log_type'] = $log_type;
  757. $data['log_doctor_id'] = $log_doctor_id;
  758. $data['log_subject_id'] = $log_subject_id;
  759. $data['log_message'] = $log_message;
  760. $data['log_resolvent'] = $log_resolvent;
  761. $data['log_add_time'] = time();
  762. $result = UserDoctorsLog::insertGetId($data);
  763. if (!empty($result)){
  764. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '添加会员医生医嘱-编号: ' . $result;
  765. plog('user-relatives-del', '会员-医生医嘱-添加会员医生医嘱', $msg);
  766. UserDoctorsLog::affairCommit();
  767. return true;
  768. }
  769. throw new \Exception('添加失败!');
  770. }catch (\Exception $exception){
  771. UserDoctorsLog::affairRollback();
  772. throw new \Exception($exception->getMessage(), 500);
  773. }
  774. }
  775. /**
  776. * Notes:会员医生医嘱列表
  777. * @param int $log_user_id
  778. * @param int $page
  779. * @param int $limit
  780. * @return array
  781. * @throws \Exception
  782. * User: ZQ
  783. * Date: 2022/12/8
  784. */
  785. public static function doctorList($log_user_id, $page, $limit)
  786. {
  787. [$list,$count] = UserDoctorsLog::doctorLogList($log_user_id, $page, $limit);
  788. if (!empty($list)){
  789. foreach ($list as $k => $v){
  790. $list[$k]['log_add_time'] = date('Y-m-d H:i:s',$v['log_add_time']);
  791. }
  792. }
  793. return compact('list', 'count');
  794. }
  795. /**
  796. * Notes:删除会员医生医嘱
  797. * @param int $log_user_id
  798. * @param int $log_id
  799. * @param int $admin_id
  800. * @return array
  801. * @throws \Exception
  802. * User: ZQ
  803. * Date: 2022/12/8
  804. */
  805. public static function doctorDel($log_user_id, $log_id, $admin_id)
  806. {
  807. UserDoctorsLog::affairBegin();
  808. try {
  809. $where = [];
  810. $where['log_id'] = $log_id;
  811. $where['log_user_id'] = $log_user_id;
  812. $result = UserDoctorsLog::where($where)->delete();
  813. if (!empty($result)){
  814. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '删除会员医生医嘱-编号: ' . $log_id;
  815. plog('user-relatives-del', '会员-医生医嘱-删除会员医生医嘱', $msg);
  816. UserDoctorsLog::affairCommit();
  817. return true;
  818. }
  819. throw new \Exception('删除失败!');
  820. }catch (\Exception $exception){
  821. UserDoctorsLog::affairRollback();
  822. throw new \Exception($exception->getMessage(), 500);
  823. }
  824. }
  825. /**
  826. * Notes:删除会员健康基础数据
  827. * @param int $data_id
  828. * @param int $data_user_id
  829. * @param int $admin_id
  830. * @return array
  831. * @throws \Exception
  832. * User: ZQ
  833. * Date: 2022/12/8
  834. */
  835. public static function healthyDel($data_user_id, $admin_id)
  836. {
  837. UserBasicHealthData::affairBegin();
  838. try {
  839. $where = [];
  840. $where['data_user_id'] = $data_user_id;
  841. $result = UserBasicHealthData::where($where)->delete();
  842. if (!empty($result)){
  843. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '删除会员健康基础数据-编号: ' . $data_user_id;
  844. plog('user-relatives-del', '会员-健康基础数据-删除会员健康基础数据', $msg);
  845. UserBasicHealthData::affairCommit();
  846. return true;
  847. }
  848. throw new \Exception('删除失败!');
  849. }catch (\Exception $exception){
  850. UserBasicHealthData::affairRollback();
  851. throw new \Exception($exception->getMessage(), 500);
  852. }
  853. }
  854. /**
  855. * Notes:修改会员健康基础数据
  856. * @param int $data_id
  857. * @param string $data_Inspection_suggestions
  858. * @param string $data_bone_density
  859. * @param string $data_tcm_testing
  860. * @param int $admin_id
  861. * @return array
  862. * @throws \Exception
  863. * User: ZQ
  864. * Date: 2022/12/8
  865. */
  866. public static function healthyUpdate($data_user_id, $data_Inspection_suggestions, $data_bone_density, $data_tcm_testing, $admin_id)
  867. {
  868. UserBasicHealthData::affairBegin();
  869. try {
  870. $where = [];
  871. $where['data_user_id'] = $data_user_id;
  872. $data = [];
  873. $data['data_update_time'] = time();
  874. $data['data_Inspection_suggestions'] = $data_Inspection_suggestions;
  875. if (!empty($data_Inspection_suggestions) && empty($data_bone_density) && empty($data_tcm_testing)){
  876. $result = UserBasicHealthData::where($where)->update($data);
  877. if (!empty($result)){
  878. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '修改会员健康基础数据-编号: ' . $data_user_id;
  879. plog('user-relatives-del', '会员-健康基础数据-修改会员健康基础数据', $msg);
  880. UserBasicHealthData::affairCommit();
  881. return true;
  882. }
  883. }elseif (!empty($data_bone_density) && empty($data_tcm_testing)){
  884. $data['data_bone_density'] = $data_bone_density;
  885. $data_type = 2;
  886. }elseif (!empty($data_tcm_testing) && empty($data_bone_density)){
  887. $data['data_tcm_testing'] = $data_tcm_testing;
  888. $data_type = 4;
  889. }elseif(!empty($data_tcm_testing) && !empty($data_bone_density)){
  890. $data['data_bone_density'] = $data_bone_density;
  891. $data['data_tcm_testing'] = $data_tcm_testing;
  892. $data_type = 3;
  893. }
  894. $result = UserBasicHealthData::where($where)->update($data);
  895. if($data_type == 3){
  896. //插入一条记录
  897. $log = UserBasicHealthData::where($where)->first();
  898. $log = json_decode($log,true);
  899. unset($log['data_id']);
  900. unset($log['data_update_time']);
  901. $log['data_type'] = 2;
  902. $log['data_add_time'] = time();
  903. unset($log['data_tcm_testing']);
  904. $id = UserBasicHealthDataLog::insertGetId($log);
  905. $log['data_type'] = 4;
  906. unset($log['data_bone_density']);
  907. $log['data_tcm_testing'] = $data_tcm_testing;
  908. $ids = UserBasicHealthDataLog::insertGetId($log);
  909. }elseif($data_type == 2 || $data_type == 4){
  910. //插入一条记录
  911. $log = UserBasicHealthData::where($where)->first();
  912. $log = json_decode($log,true);
  913. unset($log['data_id']);
  914. unset($log['data_update_time']);
  915. $log['data_type'] = $data_type;
  916. $log['data_add_time'] = time();
  917. $id = UserBasicHealthDataLog::insertGetId($log);
  918. }
  919. if (!empty($result)){
  920. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '修改会员健康基础数据-编号: ' . $data_user_id;
  921. plog('user-relatives-del', '会员-健康基础数据-修改会员健康基础数据', $msg);
  922. if(!empty($id)){
  923. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '添加会员健康基础数据记录-编号: ' . $id;
  924. plog('user-relatives-del', '会员-健康基础数据记录-添加会员健康基础数据记录', $msg);
  925. }
  926. if(!empty($ids)){
  927. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '添加会员健康基础数据记录-编号: ' . $ids;
  928. plog('user-relatives-del', '会员-健康基础数据记录-添加会员健康基础数据记录', $msg);
  929. }
  930. UserBasicHealthData::affairCommit();
  931. return true;
  932. }
  933. throw new \Exception('修改失败!');
  934. }catch (\Exception $exception){
  935. UserBasicHealthData::affairRollback();
  936. throw new \Exception($exception->getMessage(), 500);
  937. }
  938. }
  939. /**
  940. * Notes:查询会员健康基础数据
  941. * @param int $data_id
  942. * @param int $data_user_id
  943. * @return array
  944. * @throws \Exception
  945. * User: ZQ
  946. * Date: 2022/12/8
  947. */
  948. public static function healthyInfo($data_user_id)
  949. {
  950. $where = [];
  951. $where['data_user_id'] = $data_user_id;
  952. $data = UserBasicHealthData::where($where)->first();
  953. if (!empty($data)){
  954. $data['data_add_time'] = date('Y-m-d H:i:s',$data['data_add_time']);
  955. $data['data_update_time'] = $data['data_update_time'] ? date('Y-m-d H:i:s',$data['data_update_time']) : '';
  956. }
  957. return $data;
  958. }
  959. }