Product.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace app\admin\model\unishop;
  3. use think\Model;
  4. use traits\model\SoftDelete;
  5. /**
  6. * 商品模型
  7. * Class Product
  8. * @package app\admin\model\unishop
  9. */
  10. class Product extends Model
  11. {
  12. use SoftDelete;
  13. //数据库
  14. protected $connection = 'database';
  15. // 表名
  16. protected $name = 'unishop_product';
  17. // 自动写入时间戳字段
  18. protected $autoWriteTimestamp = 'int';
  19. // 定义时间戳字段名
  20. protected $createTime = 'createtime';
  21. protected $updateTime = 'updatetime';
  22. protected $deleteTime = 'deletetime';
  23. protected static function init()
  24. {
  25. self::afterInsert(function ($row) {
  26. $pk = $row->getPk();
  27. $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
  28. });
  29. }
  30. /**
  31. * 关联分类
  32. * @return \think\model\relation\BelongsTo
  33. */
  34. public function category()
  35. {
  36. return $this->belongsTo('category');
  37. }
  38. /**
  39. * 关联运费
  40. * @return \think\model\relation\BelongsTo
  41. */
  42. public function delivery()
  43. {
  44. return $this->belongsTo('delivery');
  45. }
  46. }