CustomAddr.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php namespace App\Models;
  2. use Illuminate\Database\Eloquent\Factories\HasFactory;
  3. use Illuminate\Database\Eloquent\Model;
  4. /**
  5. * 客户地址模型
  6. *
  7. */
  8. class CustomAddr extends Model
  9. {
  10. use HasFactory;
  11. // 与模型关联的表名
  12. protected $table = 'custom_addr';
  13. // 是否主动维护时间戳
  14. public $timestamps = false;
  15. // 定义时间戳字段名
  16. // const CREATED_AT = 'insert_time';
  17. // const UPDATED_AT = 'update_time';
  18. /**
  19. * 添加数据
  20. *
  21. */
  22. public function add($data)
  23. {
  24. // 时间
  25. $data['insert_time'] = time();
  26. $data['update_time'] = time();
  27. // 写入数据表
  28. $id = $this->query()->insertGetId($data);
  29. // 返回结果
  30. return $id;
  31. }
  32. /**
  33. * 添加数据
  34. *
  35. */
  36. public function edit($id,$data)
  37. {
  38. // 更新时间
  39. $data['update_time'] = time();
  40. // 写入数据表
  41. $result = $this->query()->where(['id'=>$id])->update($data);
  42. // 返回结果
  43. return $result;
  44. }
  45. /**
  46. * 添加数据
  47. *
  48. */
  49. public function del($id)
  50. {
  51. // 写入数据表
  52. $result = $this->query()->where(['id'=>$id])->delete();
  53. // 返回结果
  54. return $result;
  55. }
  56. /**
  57. * 查询某条数据
  58. *
  59. */
  60. public function getOne($id,$field=''){
  61. // 返回结果
  62. $result = $field ? $this->query()->where([['id','=',$id]])->value($field) : $this->query()->where([['id','=',$id]])->first(['id','custom_uid','contact_province','contact_city','contact_area','contact_addr','contact_name','contact_shop','contact_phone','is_default','shop_type']);
  63. // 返回结果
  64. return $result;
  65. }
  66. /**
  67. * 查询某条数据
  68. *
  69. */
  70. public function getListByCustom($uid){
  71. // 返回结果
  72. $result = $this->query()->where([['custom_uid','=',$uid]])->get(['id','custom_uid','contact_province','contact_city','contact_area','contact_addr','contact_name','contact_shop','contact_phone','is_default','shop_type']);
  73. // 返回结果
  74. return $result;
  75. }
  76. }