BatchCustomSendMsgs.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace App\Modules\OfficialAccount\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use DB;
  5. class BatchCustomSendMsgs extends Model
  6. {
  7. protected $tables = 'batch_custom_send_msgs';
  8. protected $fillable = ['name','send_time','content','redirect_url','status','subscribe_time','sex','balance','order_type','category_id','del_flag','is_full_send'];
  9. /**
  10. * 判断1小时内是否有相同的客服消息插入过
  11. */
  12. static function isSendCustomerAtSameTime($send_time)
  13. {
  14. return self::where(['del_flag'=>0])->where('status','!=','4')->where('send_time','<',date('Y-m-d H:i:s',strtotime($send_time)+3600))->where('send_time','>',date('Y-m-d H:i:s',strtotime($send_time)-3600))->first();
  15. }
  16. /**
  17. * 判断1小时内是否有相同的客服消息插入过,不同性别
  18. */
  19. static function isSendCustomerAtSameTimeSex($send_time,$sex)
  20. {
  21. return self::where(['del_flag'=>0])->where('sex',$sex)->where('status','!=','4')->where('send_time','<',date('Y-m-d H:i:s',strtotime($send_time)+3600))->where('send_time','>',date('Y-m-d H:i:s',strtotime($send_time)-3600))->first();
  22. }
  23. /**
  24. * 判断1小时内是否有相同的客服消息插入过,不同性别
  25. */
  26. static function isSendCustomerAtSameTimeSexName($send_time,$sex,$name)
  27. {
  28. return self::where(['del_flag'=>0])->where('sex',$sex)->where('status','!=','4')
  29. ->where('send_time','<',date('Y-m-d H:i:s',strtotime($send_time)+3600))
  30. ->where('send_time','>',date('Y-m-d H:i:s',strtotime($send_time)-3600))
  31. ->where('name',$name)->first();
  32. }
  33. /**
  34. * 根据渠道获取关键字列表
  35. */
  36. static function batchCustomMsgList()
  37. {
  38. return self::where('del_flag', 0)->select('batch_custom_send_msgs.*','batch_custom_send_msgs.created_at as create_time')->orderBy('id','desc')->paginate(2);
  39. }
  40. /**
  41. * 根据id获取
  42. */
  43. static function batchCustomMsgById($id)
  44. {
  45. return self::where('id', $id)->first();
  46. }
  47. /**
  48. * 更新状态
  49. */
  50. static function updateBatchCustomSendMsgStatusById($id,$status,$del_flag=0)
  51. {
  52. return self::where('id', $id)->update(['status'=>$status,'del_flag'=>$del_flag,'updated_at'=>date('Y-m-d H:i:s')]);
  53. }
  54. }