OrdersTransport.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php namespace App\Models;
  2. use Illuminate\Database\Eloquent\Factories\HasFactory;
  3. use Illuminate\Database\Eloquent\Model;
  4. /**
  5. * 订单物流
  6. */
  7. class OrdersTransport extends Model
  8. {
  9. use HasFactory;
  10. // 与模型关联的表名
  11. protected $table = 'orders_transport';
  12. // 是否主动维护时间戳
  13. public $timestamps = false;
  14. // 定义时间戳字段名
  15. // const CREATED_AT = 'insert_time';
  16. // const UPDATED_AT = 'update_time';
  17. /**
  18. * 添加数据
  19. *
  20. */
  21. public function add($data)
  22. {
  23. // 时间
  24. $data['insert_time'] = time();
  25. $data['update_time'] = time();
  26. // 写入数据表
  27. $id = $this->query()->insertGetId($data);
  28. // 返回结果
  29. return $id;
  30. }
  31. /**
  32. * 添加数据
  33. *
  34. */
  35. public function edit($id,$data)
  36. {
  37. // 更新时间
  38. $data['update_time'] = time();
  39. // 写入数据表
  40. $result = $this->query()->where(['id'=>$id])->update($data);
  41. // 返回结果
  42. return $result;
  43. }
  44. /**
  45. * 编码转id
  46. *
  47. * @param string $code 编码
  48. *
  49. */
  50. public function codeToId($code){
  51. return intval(str_ireplace('klwl','',$code));
  52. }
  53. /**
  54. * id转编码
  55. *
  56. * @param int $id 编码
  57. *
  58. */
  59. public function idToCode($id){
  60. return 'klwl'. str_pad($id, 9, '0', STR_PAD_LEFT);;
  61. }
  62. }