SystemUserTask.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. 'type' => 'ShareLevel',
  87. 'name' => '分享单数{$num}',
  88. 'real_name' => '分享单数',
  89. 'max_number' => 0,
  90. 'min_number' => 0,
  91. 'unit' => '个'
  92. ],
  93. ];
  94. public function profile()
  95. {
  96. return $this->hasOne('SystemUserLevel', 'level_id', 'id')->field('name');
  97. }
  98. public static function getTaskTypeAll()
  99. {
  100. return self::$TaskType;
  101. }
  102. /**
  103. * 获取某个任务
  104. * @param $type
  105. * @return mixed
  106. */
  107. public static function getTaskType($type)
  108. {
  109. foreach (self::$TaskType as $item) {
  110. if ($item['type'] == $type) return $item;
  111. }
  112. }
  113. /**
  114. * 设置任务名
  115. * @param $type
  116. * @param $num
  117. * @return mixed
  118. */
  119. public static function setTaskName($type, $num)
  120. {
  121. $systemType = self::getTaskType($type);
  122. return str_replace('{$num}', $num . $systemType['unit'], $systemType['name']);
  123. }
  124. /**
  125. * 获取等级会员任务列表
  126. * @param $level_id
  127. * @param $page
  128. * @param $limit
  129. * @return array
  130. */
  131. public static function getTashList($level_id, $page, $limit)
  132. {
  133. $data = self::where('level_id', $level_id)->order('sort desc,add_time desc')->page($page, $limit)->select();
  134. $data = count($data) ? $data->toArray() : [];
  135. foreach ($data as &$item) {
  136. $item['level_name'] = SystemUserLevel::where('id', $item['level_id'])->value('name');
  137. }
  138. $count = self::where('level_id', $level_id)->count();
  139. return compact('data', 'count');
  140. }
  141. }