DeveloperService.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace app\common\service;
  3. use app\admin\model\Developers;
  4. use app\common\traits\ServiceTrait;
  5. use Exception;
  6. use think\Db;
  7. class DeveloperService
  8. {
  9. use ServiceTrait;
  10. /** @var Developers */
  11. public static $Model = Developers::class;
  12. /**
  13. * 人才入驻
  14. *
  15. * @param array $data 数据
  16. * @param int $userId 用户ID
  17. * @return bool
  18. * @throws Exception
  19. */
  20. public static function create($data, $userId)
  21. {
  22. $saveData = [
  23. 'user_id' => $userId,
  24. 'job' => $data['job'] ?? '',
  25. 'tags' => implode(',', $data['tags'] ?? ''),
  26. 'work_years' => $data['work_years'] ?? 0,
  27. 'contact' => $data['contact'] ?? '',
  28. 'desc' => $data['desc'] ?? '',
  29. ];
  30. $existed = self::$Model::get(['user_id' => $userId]);
  31. if (!$existed) {
  32. $result = self::$Model::create($saveData);
  33. } else {
  34. $result = self::$Model::where('user_id', $userId)->update($saveData);
  35. }
  36. if (!$result) {
  37. throw new Exception('需求保存失败');
  38. }
  39. return true;
  40. }
  41. /**
  42. * @param $id
  43. * @return void
  44. */
  45. public static function auditPass($id)
  46. {
  47. Db::transaction(function () use ($id) {
  48. $developer = self::getOne(['id' => $id]);
  49. if (!$developer) {
  50. exception('该开发者不存在');
  51. }
  52. //修改审核状态
  53. $developer->status = CommonService::STATUS_ON;
  54. $saveRes = $developer->save();
  55. if (!$saveRes) {
  56. exception('更新审核状态失败');
  57. }
  58. //设置开发者角色
  59. $user = UserService::getOne(['id' => $developer->user_id]);
  60. $user->role = UserService::ROLE_DEV;
  61. $saveRes2 = $user->save();
  62. if (!$saveRes2) {
  63. exception('更新用户角色失败');
  64. }
  65. //发送入驻成功通知
  66. $msgData = [
  67. 'values' => [
  68. '开发者',
  69. date('Y-m-d H:i:s', $developer->createtime),
  70. '审核成功',
  71. SubscribeMessageService::MSG_MAP[SubscribeMessageService::MSG_TEMP_DEVELOPER_JOIN]['remark'],
  72. ]
  73. ];
  74. (new EasyWeChatService())->sendMsg($developer->user_id, SubscribeMessageService::MSG_TEMP_DEVELOPER_JOIN, $msgData);
  75. });
  76. }
  77. }