Condition.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace app\admin\model\lottery;
  3. use think\Model;
  4. use traits\model\SoftDelete;
  5. class Condition extends Model
  6. {
  7. use SoftDelete;
  8. // 表名
  9. protected $table = 'shop_lottery_condition';
  10. // 自动写入时间戳字段
  11. protected $autoWriteTimestamp = 'integer';
  12. // 定义时间戳字段名
  13. protected $createTime = 'createtime';
  14. protected $updateTime = 'updatetime';
  15. protected $deleteTime = 'deletetime';
  16. // 追加属性
  17. protected $append = [
  18. 'type_text',
  19. 'goods_rule_text',
  20. 'status_text'
  21. ];
  22. /**
  23. * 条件类型列表
  24. */
  25. public function getTypeList()
  26. {
  27. return [
  28. '1' => __('购买指定商品'),
  29. '2' => __('单笔订单消费满额'),
  30. '3' => __('单次充值满额'),
  31. '4' => __('活动期间累计消费满额')
  32. ];
  33. }
  34. /**
  35. * 商品规则列表
  36. */
  37. public function getGoodsRuleList()
  38. {
  39. return [
  40. '1' => __('指定商品参与'),
  41. '2' => __('指定商品不可参与')
  42. ];
  43. }
  44. /**
  45. * 状态列表
  46. */
  47. public function getStatusList()
  48. {
  49. return [
  50. '0' => __('禁用'),
  51. '1' => __('启用')
  52. ];
  53. }
  54. // 获取器
  55. public function getTypeTextAttr($value, $data)
  56. {
  57. $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
  58. $list = $this->getTypeList();
  59. return isset($list[$value]) ? $list[$value] : '';
  60. }
  61. public function getGoodsRuleTextAttr($value, $data)
  62. {
  63. $value = $value ? $value : (isset($data['goods_rule']) ? $data['goods_rule'] : '');
  64. $list = $this->getGoodsRuleList();
  65. return isset($list[$value]) ? $list[$value] : '';
  66. }
  67. public function getStatusTextAttr($value, $data)
  68. {
  69. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  70. $list = $this->getStatusList();
  71. return isset($list[$value]) ? $list[$value] : '';
  72. }
  73. // 关联关系
  74. public function activity()
  75. {
  76. return $this->belongsTo('Activity', 'activity_id', 'id');
  77. }
  78. }