Aftermarket.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 Aftermarket Extends Model {
  10. use SoftDelete;
  11. // 表名,不含前缀
  12. protected $name = 'qingdongams_aftermarket';
  13. // 开启自动写入时间戳字段
  14. protected $autoWriteTimestamp = 'int';
  15. // 定义时间戳字段名
  16. protected $createTime = 'createtime';
  17. protected $updateTime = 'updatetime';
  18. protected $deleteTime = 'deletetime';
  19. public function getTypeIdsAttr($value){
  20. return trim($value,',');
  21. }
  22. public function getImgAttr($value) {
  23. if($value){
  24. return cdnurl($value, true);
  25. }
  26. return $value;
  27. }
  28. //获取创建时间
  29. public function getCreatetimeAttr($value) {
  30. return date('Y-m-d H:i:s', $value);
  31. }
  32. //创建售后问题
  33. public static function createAftermarket($params) {
  34. $staff = Staff::info();
  35. if (!empty($staff)) {
  36. $params['create_staff_id'] = $staff->id;
  37. }
  38. $customer = new self;
  39. // 调用当前模型对应的User验证器类进行数据验证
  40. $result = $customer->allowField(true)->validate(true)->save($params);
  41. $lastId = $customer->getLastInsID();
  42. if (false === $result) {
  43. // 验证失败 输出错误信息
  44. throw new Exception($customer->getError());
  45. }
  46. return $lastId;
  47. }
  48. /**
  49. *修改售后问题
  50. */
  51. public static function updateAftermarket($params) {
  52. $customer = new self;
  53. // 调用当前模型对应的User验证器类进行数据验证
  54. $result = $customer->save($params, ['id' => $params['id']]);
  55. if (false === $result) {
  56. // 验证失败 输出错误信息
  57. throw new Exception($customer->getError());
  58. }
  59. return true;
  60. }
  61. public function product(){
  62. return $this->belongsTo(Product::class,'id','product_ids');
  63. }
  64. public function staff() {
  65. return $this->belongsTo(Staff::class, 'create_staff_id', 'id')->field('id,name,img,post');
  66. }
  67. }