AftermarketType.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace addons\qingdongams\model;
  3. use think\Exception;
  4. use think\Model;
  5. use traits\model\SoftDelete;
  6. /**
  7. * 售后问题分类管理
  8. */
  9. class AftermarketType Extends Model {
  10. use SoftDelete;
  11. // 表名,不含前缀
  12. protected $name = 'qingdongams_aftermarket_type';
  13. // 开启自动写入时间戳字段
  14. protected $autoWriteTimestamp = 'int';
  15. // 定义时间戳字段名
  16. protected $createTime = 'createtime';
  17. protected $updateTime = 'updatetime';
  18. protected $deleteTime = 'deletetime';
  19. //创建产品
  20. public static function createType($params) {
  21. $staff = Staff::info();
  22. if (!empty($staff)) {
  23. $params['create_staff_id'] = $staff->id;
  24. }
  25. $customer = new self;
  26. // 调用当前模型对应的User验证器类进行数据验证
  27. $result = $customer->allowField(true)->save($params);
  28. $lastId = $customer->getLastInsID();
  29. if (false === $result) {
  30. // 验证失败 输出错误信息
  31. throw new Exception($customer->getError());
  32. }
  33. return $lastId;
  34. }
  35. /**
  36. *修改产品
  37. */
  38. public static function updateType($params) {
  39. $customer = new self;
  40. // 调用当前模型对应的User验证器类进行数据验证
  41. $result = $customer->save($params, ['id' => $params['id']]);
  42. if (false === $result) {
  43. // 验证失败 输出错误信息
  44. throw new Exception($customer->getError());
  45. }
  46. return true;
  47. }
  48. }