UserEnter.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\model\merchant;
  12. use traits\ModelTrait;
  13. use basic\ModelBasic;
  14. use think\Url;
  15. use app\admin\model\special\Lecturer;
  16. use app\admin\model\wechat\WechatUser;
  17. use service\SystemConfigService;
  18. use service\WechatTemplateService;
  19. use app\wap\model\routine\RoutineTemplate;
  20. use app\admin\model\user\User;
  21. use app\wap\model\wap\SmsTemplate;
  22. use service\AliMessageService;
  23. /**
  24. * Class UserEnter 讲师申请
  25. * @package app\admin\model\merchant
  26. */
  27. class UserEnter extends ModelBasic
  28. {
  29. use ModelTrait;
  30. //设置where条件
  31. public static function setWhere($where, $alirs = '', $model = null)
  32. {
  33. $model = $model === null ? new self() : $model;
  34. $model = $alirs !== '' ? $model->alias($alirs) : $model;
  35. $alirs = $alirs === '' ? $alirs : $alirs . '.';
  36. $model = $model->where("{$alirs}is_del", 0);
  37. if ($where['title'] && $where['title']) $model = $model->where("{$alirs}merchant_name", 'LIKE', "%$where[title]%");
  38. return $model;
  39. }
  40. /**讲师列表
  41. * @param $where
  42. * @return array
  43. * @throws \think\Exception
  44. */
  45. public static function getLecturerList($where)
  46. {
  47. $data = self::setWhere($where)->page((int)$where['page'], (int)$where['limit'])->select();
  48. $data = count($data) ? $data->toArray() : [];
  49. foreach ($data as $key => &$value) {
  50. $value['address'] = $value['province'] . $value['city'] . $value['district'] . $value['address'];
  51. $value['success_time'] = date('Y-m-d H:i:s', $value['success_time']);
  52. $value['fail_time'] = date('Y-m-d H:i:s', $value['fail_time']);
  53. }
  54. $count = self::setWhere($where)->count();
  55. return compact('data', 'count');
  56. }
  57. /**
  58. * 删除讲师申请
  59. * @param $id
  60. * @return bool|int
  61. * @throws \think\exception\DbException
  62. */
  63. public static function delLecturer($id)
  64. {
  65. $lecturer = self::get($id);
  66. if (!$lecturer) return self::setErrorInfo('删除的数据不存在');
  67. return self::where('id', $id)->delete();
  68. }
  69. /**审核失败
  70. * @param $id
  71. * @param $fail_msg
  72. * @return bool
  73. * @throws \think\exception\DbException
  74. */
  75. public static function changeFail($id, $uid, $fail_message, $enter)
  76. {
  77. $fail_time = time();
  78. $status = -1;
  79. try {
  80. $wechat_notification_message = SystemConfigService::get('wechat_notification_message');
  81. if ($wechat_notification_message == 1) {
  82. WechatTemplateService::sendTemplate(WechatUser::uidToOpenid($uid), WechatTemplateService::EXAMINE_RESULT, [
  83. 'first' => '尊敬的用户,您提交讲师入住申请审核结果已出。',
  84. 'keyword1' => '审核失败',
  85. 'keyword2' => date('Y-m-d H:i:s', time()),
  86. 'remark' => '失败原因:' . $fail_message
  87. ], Url::build('wap/spread/spread', [], true, true));
  88. } else {
  89. $dat['phrase5']['value'] = '审核失败';
  90. $dat['time24']['value'] = date('Y-m-d H:i:s', time());
  91. $dat['thing4']['value'] = '失败原因:' . $fail_message;
  92. RoutineTemplate::sendExamineResult($dat, $uid, Url::build('wap/spread/spread', [], true, true));
  93. }
  94. } catch (\Exception $e) {
  95. }
  96. $site_name = SystemConfigService::get('site_name');
  97. $sms_platform_selection = SystemConfigService::get('sms_platform_selection');
  98. if ($sms_platform_selection == 1) {
  99. $approval_failed_template_id = SystemConfigService::get('approval_failed_template_id');//审核未通过模版ID
  100. if ($approval_failed_template_id) {
  101. $data['site_name'] = $site_name;
  102. AliMessageService::sendmsg($enter['link_tel'], $approval_failed_template_id, $data);
  103. }
  104. } else {
  105. $data['site_name'] = $site_name;
  106. $data['phone'] = $enter['link_tel'];
  107. SmsTemplate::sendSms($uid, $data, 'ENTRY_FAILED');
  108. }
  109. return self::edit(compact('fail_time', 'fail_message', 'status'), $id);
  110. }
  111. /**审核成功
  112. * @param $id
  113. * @return bool
  114. */
  115. public static function changeSuccess($id, $uid, $enter)
  116. {
  117. $success_time = time();
  118. $status = 1;
  119. try {
  120. $wechat_notification_message = SystemConfigService::get('wechat_notification_message');
  121. if ($wechat_notification_message == 1) {
  122. WechatTemplateService::sendTemplate(WechatUser::uidToOpenid($uid), WechatTemplateService::EXAMINE_RESULT, [
  123. 'first' => '尊敬的用户,您提交讲师入住申请审核结果已出。',
  124. 'keyword1' => '审核成功',
  125. 'keyword2' => date('Y-m-d H:i:s', time()),
  126. 'remark' => '感恩您的参与和支持,谢谢!'
  127. ], Url::build('wap/spread/spread', [], true, true));
  128. } else {
  129. $dat['phrase5']['value'] = '审核成功';
  130. $dat['time24']['value'] = date('Y-m-d H:i:s', time());
  131. $dat['thing4']['value'] = '感恩您的参与和支持,谢谢!';
  132. RoutineTemplate::sendExamineResult($dat, $uid, Url::build('wap/spread/spread', [], true, true));
  133. }
  134. } catch (\Exception $e) {
  135. }
  136. $site_name = SystemConfigService::get('site_name');
  137. $sms_platform_selection = SystemConfigService::get('sms_platform_selection');
  138. if ($sms_platform_selection == 1) {
  139. $approved_template_id = SystemConfigService::get('approved_template_id');//审核通过模版ID
  140. if ($approved_template_id) {
  141. $data['site_name'] = $site_name;
  142. $data['phone'] = $enter['link_tel'];
  143. $data['pwd'] = '123456';
  144. AliMessageService::sendmsg($enter['link_tel'], $approved_template_id, $data);
  145. }
  146. } else {
  147. $site_name = SystemConfigService::get('site_name');
  148. $data['site_name'] = $site_name;
  149. $data['phone'] = $enter['link_tel'];
  150. $data['pwd'] = '123456';
  151. SmsTemplate::sendSms($uid, $data, 'SETTLED_THROUGH');
  152. }
  153. return self::edit(compact('status', 'success_time'), $id);
  154. }
  155. }