| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 | <?phpnamespace app\admin\server\life;use app\admin\model\LifeFarmGoods;use app\admin\model\SystemMenu;use support\Redis;class FarmGoodsServer{    /**     * Notes:获取绿色蔬菜列表     * @param string $keywords     * @param int $page     * @param int $limit     * @return array     * User: YCP     * Date: 2022/11/4     */    public static function getFarmGoodsList(int $page, int $limit, string $keywords)    {        [$list, $count] =  LifeFarmGoods::getFarmGoodsList($page, $limit, $keywords);        return compact('list', 'page', 'limit', 'count');    }    /**     * Notes: 添加绿色蔬菜     * @param string $goods_name     * @param array $goods_rules     * @return int     * User: YCP     * Date: 2022/11/4     */    public static function insertFarmGoods(array $params, int $admin_id)    {        LifeFarmGoods::affairBegin();        try {            $params['goods_create_time'] = time();            $result =  LifeFarmGoods::insertGetId($params);            if (!empty($result)){                $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '添加生态农场绿色蔬菜-编号: ' . $result;                plog('life-farmgoods-create', '悦活-生态农场绿色蔬菜', $msg);                LifeFarmGoods::affairCommit();                return $result;            }            throw new \Exception('操作失败!');        }catch (\Exception $exception){            LifeFarmGoods::affairRollback();            throw new \Exception($exception->getMessage(), 500);        }    }    /**     * Notes:修改绿色蔬菜     * @param string $goods_name     * @param int $goods_id     * @return int     * User: YCP     * Date: 2022/11/4     */    public static function updateFarmGoods(array $params, int $admin_id)    {        LifeFarmGoods::affairBegin();        try {                        $where = [];            $where['goods_id'] = $params['goods_id'];            $info = LifeFarmGoods::where($where)->first();            if(empty($info) || $info === false)            {                throw new \Exception('信息不存在');            }            $params['goods_update_time'] = time();            $result = LifeFarmGoods::where($where)->update($params);            if ($result !== false){                $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '修改生态农场绿色蔬菜-编号: ' . $params['goods_id'];                plog('life-farmgoods-update', '悦活-修改生态农场绿色蔬菜', $msg);                LifeFarmGoods::affairCommit();                return true;            }            throw new \Exception('操作失败!');        }catch (\Exception $exception){            LifeFarmGoods::affairRollback();            throw new \Exception($exception->getMessage(), 500);        }    }    /**     * Notes:删除绿色蔬菜     * @param int $goods_id     * @return int     * User: YCP     * Date: 2022/11/4     */    public static function delFarmGoods($goods_id,$admin_id)    {        LifeFarmGoods::affairBegin();        try {            $where = [];            $where['goods_id'] = $goods_id;            $data['goods_is_del'] = 1;            $result = LifeFarmGoods::where($where)->update($data);            if (!empty($result)){                $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '删除生态农场绿色蔬菜-编号: ' . $goods_id;                plog('life-farmgoods-delete', '悦活-删除生态农场绿色蔬菜', $msg);                LifeFarmGoods::affairCommit();                return true;            }else{                return false;            }        }catch (\Exception $exception){            LifeFarmGoods::affairRollback();            throw new \Exception($exception->getMessage(), 500);        }    }    /**     * Notes:查询绿色蔬菜     * @param int $goods_id     * @return int     * User: YCP     * Date: 2022/11/4     */    public static function farmGoodsInfo($goods_id)    {        $where = [];        $where['goods_id'] = $goods_id;        $result = LifeFarmGoods::with(['Shop','Category','MedicalCarePostage'])->where($where)->first();        if(empty($result) || $result === false)        {            throw new \Exception('信息不存在');        }        return $result;    }    /**     * Notes:修改状态     * @param string $food_name     * @param int $food_status     * @return int     * User: YCP     * Date: 2022/11/7     */    public static function updateStatus($goods_id, $goods_status)    {        LifeFarmGoods::affairBegin();        try {            $where = [];            $where['goods_id'] = $goods_id;            $data = [];            $data['goods_status'] = $goods_status;            $result = LifeFarmGoods::where($where)->update($data);            if ($result !== false){                LifeFarmGoods::affairCommit();                return true;            }            throw new \Exception('操作失败!');        }catch (\Exception $exception){            LifeFarmGoods::affairRollback();            throw new \Exception($exception->getMessage(), 500);        }    }}
 |