CustomAmountRecord.php 1.6 KB

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