IntelligenceEquipment.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace app\admin\model;
  3. use support\Model;
  4. /**
  5. * 会员智能设备消息推送日志模型
  6. * Class Users
  7. * @package app\admin\model
  8. */
  9. class IntelligenceEquipment extends Model
  10. {
  11. /**
  12. * The table associated with the model.
  13. *
  14. * @var string
  15. */
  16. protected $table = 'user_intelligence_equipment';
  17. public $timestamps = false;
  18. /**
  19. * Notes:会员智能设备数据查询
  20. * @return int
  21. * User: ZQ
  22. * Date: 2022/9/19
  23. */
  24. public static function equipmentList(int $page,int $limit,$equipment_user_id, $equipment_name, $equipment_class,$equipment_tripartite_sn,$equipment_create_time)
  25. {
  26. $list = static::select(['user_intelligence_equipment.*','user.user_nickname','intelligence_products.product_name','user.user_phone'])
  27. ->where(['equipment_del'=>0])
  28. ->leftJoin('user','user_id','=','user_intelligence_equipment.equipment_user_id')
  29. ->leftJoin('intelligence_products','product_id','=','user_intelligence_equipment.equipment_intelligence_id')
  30. ->when($equipment_user_id != '', function ($query) use ($equipment_user_id){
  31. $query->where('equipment_user_id', $equipment_user_id);
  32. })
  33. ->when($equipment_class != '', function ($query) use ($equipment_class){
  34. $query->where('equipment_class', $equipment_class);
  35. })
  36. ->when($equipment_name != '', function ($query) use ($equipment_name){
  37. $query->where('equipment_name', 'like', '%'.$equipment_name.'%');
  38. })
  39. ->when($equipment_tripartite_sn != '', function ($query) use ($equipment_tripartite_sn){
  40. $query->where('equipment_tripartite_sn',$equipment_tripartite_sn);
  41. })
  42. ->when($equipment_create_time != '', function ($query) use ($equipment_create_time){
  43. $start = strtotime($equipment_create_time);
  44. $end = $start+24*60*60;
  45. $query->whereBetween('equipment_create_time',[$start,$end]);
  46. })
  47. ->forPage($page, $limit)
  48. ->orderBy('equipment_create_time','DESC')
  49. ->get();
  50. $count = static::select()
  51. ->where(['equipment_del'=>0])
  52. ->when($equipment_user_id != '', function ($query) use ($equipment_user_id){
  53. $query->where('equipment_user_id', $equipment_user_id);
  54. })
  55. ->when($equipment_class != '', function ($query) use ($equipment_class){
  56. $query->where('equipment_class', $equipment_class);
  57. })
  58. ->when($equipment_name != '', function ($query) use ($equipment_name){
  59. $query->where('equipment_name', 'like', '%'.$equipment_name.'%');
  60. })
  61. ->when($equipment_tripartite_sn != '', function ($query) use ($equipment_tripartite_sn){
  62. $query->where('equipment_tripartite_sn',$equipment_tripartite_sn);
  63. })
  64. ->when($equipment_create_time != '', function ($query) use ($equipment_create_time){
  65. $start = strtotime($equipment_create_time);
  66. $end = $start+24*60*60;
  67. $query->whereBetween('equipment_create_time',[$start,$end]);
  68. })
  69. ->count();
  70. return [$list,$count];
  71. }
  72. /**
  73. * Notes:会员智能设备数据详情
  74. * @return int
  75. * User: ZQ
  76. * Date: 2022/9/23
  77. */
  78. public static function equipmentInfor(array $where)
  79. {
  80. return static::where($where)
  81. ->leftJoin('user','user_id','=','user_intelligence_equipment.equipment_user_id')
  82. ->leftJoin('intelligence_products','product_id','=','user_intelligence_equipment.equipment_intelligence_id')
  83. ->first(['user_intelligence_equipment.*','user.user_nickname','intelligence_products.product_name','user.user_phone']);
  84. }
  85. /**
  86. * Notes:会员智能设备数据插入
  87. * @return int
  88. * User: ZQ
  89. * Date: 2022/9/19
  90. */
  91. public static function equipmentInsert($data)
  92. {
  93. $id = static::insertGetId($data);
  94. return $id;
  95. }
  96. }