$shopId]); // 店员 if (count($data['staff_commission_steps']) > 2) { // 最多2级 $this->error = '店员阶梯数最多2级'; return false; } if (!empty($data['staff_commission_steps'])) { // 添加 $dataset = []; foreach ($data['staff_commission_steps'] as $key=>$item) { $step = $key+1; $dataset[] = [ 'shop_id' => $shopId, 'role' => User::SHOP_SELLER, 'step' => $step, 'sale_amount' => $item['sale_amount'] * 10000, 'bonus_ratio' => $item['bonus_ratio'], ]; } (new static)->addAll($dataset); } // 门店身份 if (count($data['identity_commission_steps']) > 2) { // 最多2级 $this->error = '阶梯数最多2级'; return false; } if (!empty($data['identity_commission_steps'])) { // 添加 $dataset = []; foreach ($data['identity_commission_steps'] as $key=>$item) { $step = $key+1; $dataset[] = [ // 店老板 'shop_id' => $shopId, 'role' => User::SHOP_BOSS, 'step' => $step, 'sale_amount' => $item['sale_amount'] * 10000, 'bonus_ratio' => $item['boss_bonus_ratio'], ]; $dataset[] = [ // 店长 'shop_id' => $shopId, 'role' => User::SHOP_MG, 'step' => $step, 'sale_amount' => $item['sale_amount'] * 10000, 'bonus_ratio' => $item['manager_bonus_ratio'], ]; $dataset[] = [ // 厨师 'shop_id' => $shopId, 'role' => User::SHOP_CHEF, 'step' => $step, 'sale_amount' => $item['sale_amount'] * 10000, 'bonus_ratio' => $item['chef_bonus_ratio'], ]; } (new static)->addAll($dataset); } Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); $this->error = $e->getMessage(); return false; } } /** * 获取门店阶梯佣金配置 * 适用于:门店分佣配置页面 */ public function getCommissionSteps($shopId) { // 店员阶梯 $staff_commission_steps = self::where('shop_id', $shopId) ->where('role', User::SHOP_SELLER) ->order('step', 'asc') ->field('step,round(sale_amount/10000, 2) as sale_amount,bonus_ratio') ->select(); // 店老板、店长、其他身份阶梯 $identity_commission_steps = self::where('shop_id', $shopId) ->where('role', '<>', User::SHOP_SELLER) ->where('role', '>', User::NORMAL_USER) ->where('role', '<', User::COMMISSION_USER) ->order(['step' => 'asc', 'role' => 'asc']) ->field('role,step,sale_amount,bonus_ratio') ->select(); $res_identity_commission_steps = []; if (!empty($identity_commission_steps)) { foreach($identity_commission_steps as $item) { $res_steps['step'] = $item['step']; $res_steps['sale_amount'] = helper::bcsub($item['sale_amount'] / 10000, 0, 2); if ($item['role'] == User::SHOP_BOSS) { $res_steps['boss_bonus_ratio'] = $item['bonus_ratio']; } if ($item['role'] == User::SHOP_MG) { $res_steps['manager_bonus_ratio'] = $item['bonus_ratio']; } if ($item['role'] == User::SHOP_CHEF) { $res_steps['chef_bonus_ratio'] = $item['bonus_ratio']; } $res_identity_commission_steps[$item['step']] = $res_steps; } } $data['staff_commission_steps'] = $staff_commission_steps; $data['identity_commission_steps'] = array_values($res_identity_commission_steps); return $data; } }