UsersServer.php 41 KB

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