SystemUserTask.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /**
  3. * @author: xaboy<365615158@qq.com>
  4. * @day: 2017/11/13
  5. */
  6. namespace app\admin\model\system;
  7. use crmeb\traits\ModelTrait;
  8. use crmeb\basic\BaseModel;
  9. /**
  10. * 设置等级任务 model
  11. * Class SystemUserTask
  12. * @package app\admin\model\system
  13. */
  14. class SystemUserTask extends BaseModel
  15. {
  16. /**
  17. * 数据表主键
  18. * @var string
  19. */
  20. protected $pk = 'id';
  21. /**
  22. * 模型名称
  23. * @var string
  24. */
  25. protected $name = 'system_user_task';
  26. use ModelTrait;
  27. /**
  28. * 任务类型
  29. * type 记录在数据库中用来区分任务
  30. * name 任务名 (任务名中的{$num}会自动替换成设置的数字 + 单位)
  31. * max_number 最大设定数值 0为不限定
  32. * min_number 最小设定数值
  33. * unit 单位
  34. * @var array
  35. */
  36. protected static $TaskType = [
  37. [
  38. 'type' => 'SatisfactionIntegral',
  39. 'name' => '满足积分{$num}',
  40. 'real_name' => '积分数',
  41. 'max_number' => 0,
  42. 'min_number' => 0,
  43. 'unit' => '分'
  44. ],
  45. [
  46. 'type' => 'ConsumptionAmount',
  47. 'name' => '消费满{$num}',
  48. 'real_name' => '消费金额',
  49. 'max_number' => 0,
  50. 'min_number' => 0,
  51. 'unit' => '元'
  52. ],
  53. [
  54. 'type' => 'ConsumptionFrequency',
  55. 'name' => '消费{$num}',
  56. 'real_name' => '消费次数',
  57. 'max_number' => 0,
  58. 'min_number' => 0,
  59. 'unit' => '次'
  60. ],
  61. [
  62. 'type' => 'CumulativeAttendance',
  63. 'name' => '累计签到{$num}',
  64. 'real_name' => '累计签到',
  65. 'max_number' => 365,
  66. 'min_number' => 1,
  67. 'unit' => '天'
  68. ],
  69. [
  70. 'type' => 'InviteGoodFriends',
  71. 'name' => '邀请好友{$num}成为下线',
  72. 'real_name' => '邀请好友成为下线',
  73. 'max_number' => 1000,
  74. 'min_number' => 1,
  75. 'unit' => '人'
  76. ],
  77. [
  78. 'type' => 'InviteGoodFriendsLevel',
  79. 'name' => '邀请好友{$num}成为会员',
  80. 'real_name' => '邀请好友成为会员',
  81. 'max_number' => 1000,
  82. 'min_number' => 1,
  83. 'unit' => '人'
  84. ],
  85. ];
  86. public function profile()
  87. {
  88. return $this->hasOne('SystemUserLevel', 'level_id', 'id')->field('name');
  89. }
  90. public static function getTaskTypeAll()
  91. {
  92. return self::$TaskType;
  93. }
  94. /**
  95. * 获取某个任务
  96. * @param $type
  97. * @return mixed
  98. */
  99. public static function getTaskType($type)
  100. {
  101. foreach (self::$TaskType as $item) {
  102. if ($item['type'] == $type) return $item;
  103. }
  104. }
  105. /**
  106. * 设置任务名
  107. * @param $type
  108. * @param $num
  109. * @return mixed
  110. */
  111. public static function setTaskName($type, $num)
  112. {
  113. $systemType = self::getTaskType($type);
  114. return str_replace('{$num}', $num . $systemType['unit'], $systemType['name']);
  115. }
  116. /**
  117. * 获取等级会员任务列表
  118. * @param $level_id
  119. * @param $page
  120. * @param $limit
  121. * @return array
  122. */
  123. public static function getTashList($level_id, $page, $limit)
  124. {
  125. $data = self::where('level_id', $level_id)->order('sort desc,add_time desc')->page($page, $limit)->select();
  126. $data = count($data) ? $data->toArray() : [];
  127. foreach ($data as &$item) {
  128. $item['level_name'] = SystemUserLevel::where('id', $item['level_id'])->value('name');
  129. }
  130. $count = self::where('level_id', $level_id)->count();
  131. return compact('data', 'count');
  132. }
  133. }