SetmealIncrementsRepository.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: wuzhenke
  5. * Date: 2018/11/12
  6. * Time: 19:09
  7. */
  8. namespace App\Repositories;
  9. use App\Models\SetmealIncrement;
  10. use Prettus\Repository\Criteria\RequestCriteria;
  11. use Prettus\Repository\Eloquent\BaseRepository;
  12. use Illuminate\Support\Facades\Cache;
  13. class SetmealIncrementsRepository extends BaseRepository
  14. {
  15. //增值包单位
  16. public $service_unit = array('download_resume' => '条', 'sms' => '条', 'stick' => '天', 'emergency' => '天', 'auto_refresh_jobs' => '次','jobfair_num'=>'次','jobs'=>'条');
  17. public $cate_arr = ['download_resume' => '简历增值包','jobs'=>'职位增值包','jobfair_num'=>'招聘会场次增值包', 'sms' => '短信增值包', 'stick' => '职位置顶', 'emergency' => '职位紧急', 'tpl' => '企业模板', 'auto_refresh_jobs' => '职位智能刷新'];
  18. public function model()
  19. {
  20. return SetmealIncrement::class;
  21. }
  22. public function boot()
  23. {
  24. $this->pushCriteria(app(RequestCriteria::class));
  25. }
  26. public function getCat($cat)
  27. {
  28. return $this->model->where(['cat'=>$cat])->first();
  29. }
  30. public function getIncrement($id)
  31. {
  32. return $this->model->where(['id'=>$id])->first();
  33. }
  34. public function getIncrementCache($cat = '', $id = 0)
  35. {
  36. //除掉缓存
  37. $rst = $this->model->orderBy('sort', 'desc')->get();
  38. $cache = null;
  39. if ($rst) {
  40. foreach ($rst as $k => $v) {
  41. $cache[$v->id] = $v;
  42. }
  43. }
  44. if ($cat <> '') {
  45. $return = array();
  46. foreach ($cache as $key => $value) {
  47. if ($value->cat == $cat) {
  48. $return[] = $value;
  49. }
  50. }
  51. } else {
  52. $return = $cache;
  53. }
  54. if ($id > 0) {
  55. return $return[$id];
  56. } else {
  57. return $return;
  58. }
  59. }
  60. public function getIncrementCategory()
  61. {
  62. return $this->model->select(['cat'])->groupBy('cat')->get();
  63. }
  64. }