Supplier.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace app\admin\model\equipment;
  3. use think\Model;
  4. use traits\model\SoftDelete;
  5. class Supplier extends Model
  6. {
  7. use SoftDelete;
  8. // 表名
  9. protected $name = 'equipment_supplier';
  10. // 自动写入时间戳字段
  11. protected $autoWriteTimestamp = 'int';
  12. // 定义时间戳字段名
  13. protected $createTime = 'createtime';
  14. protected $updateTime = 'updatetime';
  15. protected $deleteTime = 'deletetime';
  16. // 追加属性
  17. protected $append = [
  18. 'relationship_text',
  19. 'status_text'
  20. ];
  21. public function getRelationshipList()
  22. {
  23. return [
  24. 'special' => __('Special'),
  25. 'important' => __('Important'),
  26. 'general' => __('General'),
  27. 'standby' => __('Standby')
  28. ];
  29. }
  30. public function getRelationshipTextAttr($value, $data)
  31. {
  32. $value = $value ? $value : (isset($data['relationship']) ? $data['relationship'] : '');
  33. $list = $this->getRelationshipList();
  34. return isset($list[$value]) ? $list[$value] : '';
  35. }
  36. public function getStatusList()
  37. {
  38. return ['normal' => __('Normal'), 'hidden' => __('Hidden')];
  39. }
  40. public function getStatusTextAttr($value, $data)
  41. {
  42. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  43. $list = $this->getStatusList();
  44. return isset($list[$value]) ? $list[$value] : '';
  45. }
  46. public function getSelectpicker()
  47. {
  48. $where = ['status' => 'normal'];
  49. return $this::where($where)->order('id desc')->column('id, concat("【", supplier_code, "】", name)');
  50. }
  51. }