Aftermarket.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. public function getAnnexAttr($value) {
  29. if($value){
  30. return cdnurl($value, true);
  31. }
  32. return $value;
  33. }
  34. //获取创建时间
  35. public function getCreatetimeAttr($value) {
  36. return date('Y-m-d H:i:s', $value);
  37. }
  38. //创建售后问题
  39. public static function createAftermarket($params) {
  40. $staff = Staff::info();
  41. if (!empty($staff)) {
  42. $params['create_staff_id'] = $staff->id;
  43. }
  44. $customer = new self;
  45. // 调用当前模型对应的User验证器类进行数据验证
  46. $result = $customer->allowField(true)->validate(true)->save($params);
  47. $lastId = $customer->getLastInsID();
  48. if (false === $result) {
  49. // 验证失败 输出错误信息
  50. throw new Exception($customer->getError());
  51. }
  52. return $lastId;
  53. }
  54. /**
  55. *修改售后问题
  56. */
  57. public static function updateAftermarket($params) {
  58. $customer = new self;
  59. // 调用当前模型对应的User验证器类进行数据验证
  60. $result = $customer->save($params, ['id' => $params['id']]);
  61. if (false === $result) {
  62. // 验证失败 输出错误信息
  63. throw new Exception($customer->getError());
  64. }
  65. return true;
  66. }
  67. public function product(){
  68. return $this->belongsTo(Product::class,'id','product_ids');
  69. }
  70. public function staff() {
  71. return $this->belongsTo(Staff::class, 'create_staff_id', 'id')->field('id,name,img,post');
  72. }
  73. }