| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- <?php
- namespace app\weixin\model;
- use app\weixin\service\PRedis;
- use think\Db;
- use think\Model;
- class Meals extends Model
- {
- protected $table = 'sg_meals';
- /**
- * 获取套餐列表
- * @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($type){
- $cacheKey = "cache:meals:type_{$type}";
- $dataList = PRedis::get($cacheKey);
- if($dataList){
- return $dataList;
- }
- $where = ['status'=> 1];
- if($type){
- $where['type'] = $type;
- }
- $dataList = Meals::where($where)
- ->field('id,name,price,type,time')
- ->select()
- ->each(function($item){
- $item['price'] = round($item['price'], 2);
- });
- $dataList = $dataList? $dataList->toArray() : [];
- if($dataList){
- PRedis::set($cacheKey, $dataList, 3 * 24 * 3600);
- }
- return $dataList;
- }
- }
|