// +---------------------------------------------------------------------- declare (strict_types=1); namespace app\api\model\shop; use app\api\model\User; use app\common\model\Shops as ShopModel; use think\facade\Db; use app\common\model\chef\ChefAreas as RegionModel; /** * 商品模型 * Class Goods * @package app\api\model */ class Shops extends ShopModel { /** * 隐藏字段 * @var array */ public $hidden = [ 'create_time', 'update_time', ]; // 追加字段 protected $append = ['region']; public function getRegionAttr($value, $data) { $regionNames = $this->getRegionNames($data); return "{$regionNames['province']}{$regionNames['city']}{$regionNames['region']}"; } /** * 获取省市区名称 * @param array $data * @return mixed */ private function getRegionNames(array $data) { static $dataset = []; $id = $data[$this->getPk()]; if (!isset($dataset[$id])) { $dataset[$id] = [ 'province' => RegionModel::getNameById($data['province_id']), 'city' => RegionModel::getNameById($data['city_id']), 'region' => RegionModel::getNameById($data['region_id']), ]; } return $dataset[$id]; } public static function addBonusPool($shop_id,$money){ $shop = Shops::find($shop_id); //提现余额也要累加计算 $shop->bonus_pool = Db::raw('bonus_pool+'.$money); $shop->save(); } /** * 解聘店长 * @param $mgUserId * @param $shopId * @return bool */ public function dissMg($mgUserId,$shopId){ Db::transaction(function () use ($mgUserId,$shopId) { User::where('user_id',$mgUserId)->update(['role'=>User::NORMAL_USER,'shop_id'=>0]); Shops::where('shop_id',$shopId)->update(['manager_user_id'=>0]); }); return true; } }