HeartMeal.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace app\weixin\model;
  3. use app\weixin\service\PRedis;
  4. use think\Model;
  5. class HeartMeal extends Model
  6. {
  7. protected $table = 'sg_heart_meals';
  8. /**
  9. * 获取信息
  10. * @param $where 条件
  11. * @param string $field 字段
  12. * @return array|false|\PDOStatement|string|Model
  13. */
  14. public static function getInfo($where, $field = "*")
  15. {
  16. $info = self::where($where)->field($field)->find();
  17. return $info? $info->toArray() : [];
  18. }
  19. /**
  20. * 获取套餐列表
  21. * @return array|bool|\PDOStatement|string|\think\Collection
  22. * @throws \think\db\exception\DataNotFoundException
  23. * @throws \think\db\exception\ModelNotFoundException
  24. * @throws \think\exception\DbException
  25. */
  26. public static function getList(){
  27. $cacheKey = "cache:heartMeals";
  28. $dataList = PRedis::get($cacheKey);
  29. if($dataList){
  30. return $dataList;
  31. }
  32. $where = ['status'=> 1];
  33. $dataList = HeartMeal::where($where)
  34. ->field('id,name,price,heart,limit_buy,give,remark')
  35. ->select()
  36. ->each(function($item){
  37. $item['price'] = round($item['price'], 2);
  38. });
  39. $dataList = $dataList? $dataList->toArray() : [];
  40. if($dataList){
  41. PRedis::set($cacheKey, $dataList, 3600);
  42. }
  43. return $dataList;
  44. }
  45. }