| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?php
- namespace app\weixin\model;
- use app\weixin\service\PRedis;
- use think\Model;
- class HeartMeal extends Model
- {
- protected $table = 'sg_heart_meals';
- /**
- * 获取信息
- * @param $where 条件
- * @param string $field 字段
- * @return array|false|\PDOStatement|string|Model
- */
- public static function getInfo($where, $field = "*")
- {
- $info = self::where($where)->field($field)->find();
- return $info? $info->toArray() : [];
- }
- /**
- * 获取套餐列表
- * @return array|bool|\PDOStatement|string|\think\Collection
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public static function getList(){
- $cacheKey = "cache:heartMeals";
- $dataList = PRedis::get($cacheKey);
- if($dataList){
- return $dataList;
- }
- $where = ['status'=> 1];
- $dataList = HeartMeal::where($where)
- ->field('id,name,price,heart,limit_buy,give,remark')
- ->select()
- ->each(function($item){
- $item['price'] = round($item['price'], 2);
- });
- $dataList = $dataList? $dataList->toArray() : [];
- if($dataList){
- PRedis::set($cacheKey, $dataList, 3600);
- }
- return $dataList;
- }
- }
|