123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- // +----------------------------------------------------------------------
- // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
- // +----------------------------------------------------------------------
- // | Author: 萤火科技 <admin@yiovo.com>
- // +----------------------------------------------------------------------
- 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;
- }
- }
|