AjaxController.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2018/10/17
  6. * Time: 15:07
  7. */
  8. namespace App\Admin\Controllers\Company;
  9. use App\Http\Controllers\Controller;
  10. use App\Models\Company;
  11. use App\Models\Jobs;
  12. use App\Models\Member;
  13. use App\Models\Pms;
  14. use App\Models\Resume;
  15. use App\Models\SmsRule;
  16. use App\Repositories\SmsTemplateRepository;
  17. use App\Services\Common\EmailService;
  18. use App\Services\Common\SmsService;
  19. use Encore\Admin\Facades\Admin;
  20. use Illuminate\Http\Request;
  21. class AjaxController extends Controller
  22. {
  23. protected $smsService;
  24. protected $smsTemplateRepository;
  25. protected $emailService;
  26. /**
  27. * AjaxController constructor.
  28. * @param $smsService
  29. * @param $smsTemplateRepository
  30. */
  31. public function __construct(SmsService $smsService, SmsTemplateRepository $smsTemplateRepository, EmailService $emailService)
  32. {
  33. $this->smsService = $smsService;
  34. $this->smsTemplateRepository = $smsTemplateRepository;
  35. $this->emailService = $emailService;
  36. }
  37. public function getInfo(Request $request)
  38. {
  39. if ($request->utype == 1) {
  40. $data['info'] = Company::findOrFail($request->id);
  41. $data['utype'] =1;
  42. } else {
  43. $data['info'] = Member::findOrFail($request->id);
  44. $data['utype'] = 2;
  45. }
  46. return view('admin.ajax.getInfo')->with('info', $data);
  47. }
  48. public function getPromotion(Request $request)
  49. {
  50. $where = [];
  51. if ($request->id) {
  52. $where[] =['id', '=', $request->id];
  53. }
  54. if ($request->jobs_name) {
  55. $where[] =['jobs_name', 'like', "%$request->jobs_name%"];
  56. }
  57. if ($request->company_id) {
  58. $where[] =['company_id', '=', $request->company_id];
  59. }
  60. if ($request->company_name) {
  61. $where[] =['company_name', 'like', "%$request->company_name%"];
  62. }
  63. if ($where) {
  64. $where['valid'] = 1;
  65. $where['audit'] = 1;
  66. $where['display'] = 1;
  67. $where['subsite_id'] = get_subsite_id();
  68. $data = Jobs::select('id', 'company_id', 'jobs_name', 'company_name', 'deadline', 'created_at', 'refresh_time')->where($where)->get();
  69. if (!$data->isEmpty()) {
  70. return json_encode(['data'=>$data, 'code'=>1]);
  71. }
  72. }
  73. return json_encode(['msg'=>'<tr><td colspan="5">暂无数据</td></tr>', 'code'=>0]);
  74. }
  75. public function getResume(Request $request)
  76. {
  77. $where = [];
  78. if ($request->id) {
  79. $where[] =['id', '=', $request->id];
  80. }
  81. if ($request->fullname) {
  82. $where[] =['fullname', 'like', "%$request->fullname%"];
  83. }
  84. if ($request->uid) {
  85. $where[] =['uid', '=', $request->uid];
  86. }
  87. if ($where) {
  88. $where[] = ['audit','=',2];
  89. $where[] = ['subsite_id', '=',get_subsite_id()];
  90. $data = Resume::select('id', 'uid', 'fullname', 'created_at', 'updated_at')->where($where)->get()->toArray();
  91. }
  92. if (!empty($data)) {
  93. return json_encode(['data'=>$data, 'code'=>1]);
  94. }
  95. return json_encode(['msg'=>'<tr><td colspan="5">暂无数据</td></tr>', 'code'=>0]);
  96. }
  97. /**发送站内信
  98. * @param Request $request
  99. * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  100. */
  101. public function sendSys(Request $request)
  102. {
  103. $psm = new Pms();
  104. $data = $request->except(['_token']);
  105. $company = Company::where('id', $data['uid'])->first();
  106. $psm->utype = 1;
  107. $psm->msgtype = 1;
  108. $psm->msgfromuid = Admin::user()->id;
  109. $psm->msgfrom = Admin::user()->username;
  110. $psm->msgtoname = $company->username;
  111. $psm->msgtouid = $company->id;
  112. $psm->message = $data['body'];
  113. if ($psm->save()) {
  114. admin_toastr('站内信发送成功', 'success');
  115. return redirect(route("company.index"));
  116. }
  117. admin_toastr('站内信发送失败', 'error');
  118. return back();
  119. }
  120. public function sendEmail(Request $request)
  121. {
  122. $email = $request->email;
  123. $title = $request->title;
  124. $body = $request->body;
  125. $this->emailService->sendMail($email, EmailService::TEMPLATE_SEND_CONTENT, ['title'=>$title], ['content'=>$body]);
  126. admin_toastr('邮件发送成功', 'success');
  127. return back();
  128. }
  129. public function sendSms(Request $request)
  130. {
  131. $mobile = $request->mobile;
  132. $body = $request->body;
  133. $sms_id = $request->sms_id;
  134. // $sms_alias = $this->smsTemplateRepository->findWhere(['id'=>$sms_id], ['alias']);
  135. $SmsRule = SmsRule::where('alias', $sms_id)->first();
  136. if (isset($SmsRule->status) && !empty($SmsRule->status)) {
  137. $this->smsService->sendSms($mobile, $sms_id, ['content'=>$body]);
  138. admin_toastr('短信发送成功', 'success');
  139. } else {
  140. admin_toastr('请先开启短信-短信规则配置!', 'error');
  141. }
  142. return back();
  143. }
  144. }