[0, 1]], [['pay_type'], 'in', 'range' => [0, 1, 2, 3]] ]; } public function attributeLabels() { return [ 'store_id' => 'Store Id', 'super_sales_direct_profit' => '直推佣金比例', 'super_sales_group_profit' => '成团佣金比例', 'super_sales_bg' => '超级卖货系统背景', 'pay_type' => '提现方式【0微信 1支付宝 2微信&支付宝】', 'bank' => '是否开启银行卡提现', 'lg' => '是否开启灵工提现', 'remaining_sum' => '是否开启余额提现', 'cash_service_charge' => '提现手续费', 'min_money' => '最少提现金额', 'cash_max_single_day' => '每日提现上限', 'cash_max_day' => '平台提现上限', 'goods_ids' => '商品ID', 'upgrade_direct_profit' => '是否立即升级' ]; } public function settingIndex() { try { $store_id = $this->store_id; $data = [ 'super_sales_direct_profit' => 0, 'super_sales_group_profit' => 0, 'pay_type' => '', 'bank' => 0, 'remaining_sum' => 0, 'lg' => 0, 'cash_service_charge' => 0, 'min_money' => 0, 'cash_max_single_day' => 0, 'cash_max_day' => 0, 'goods_ids' => '', 'cash_price_type' => '1', 'cash_price_amount' => 100, 'cash_price_integral' => 0, 'cash_price_balance' => 0, 'upgrade_direct_profit' => '', 'super_sales_bg' => '' ]; $super_sales_setting = Option::get('super_sales_setting', $store_id, 'super_sales')['value']; $super_sales_setting = json_decode($super_sales_setting ?? '', true); if (empty($super_sales_setting)) { $super_sales_setting = $data; } $super_sales_setting['goods_info'] = []; $goods_ids = explode(',', $super_sales_setting['goods_ids'] ?? ''); if (!empty($goods_ids)) { $goods = Goods::find()->where(['id' => $goods_ids, 'is_delete' => 0, 'store_id' => $store_id]) ->select('id, name, cover_pic, price, goods_num')->asArray()->all(); foreach ($goods as &$item) { $goods_cat = GoodsCat::find()->alias('gc') ->leftJoin(['c' => Cat::tableName()], 'gc.cat_id=c.id') ->where([ 'gc.goods_id' => $item['id'], 'c.is_delete' => 0, 'gc.is_delete' => 0, 'c.store_id' => $store_id]) ->select(['c.name']) ->column(); $item['cat'] = implode(' ', $goods_cat); } $super_sales_setting['goods_info'] = $goods; } return [ 'code' => 0, 'msg' => '获取成功', 'data' => $super_sales_setting ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } public function settingEdit() { try { $store_id = $this->store_id; if (!$this->validate()) { throw new \Exception($this->getErrorSummary(false)[0]); } $data = [ 'super_sales_direct_profit' => floatval($this->super_sales_direct_profit), 'super_sales_group_profit' => floatval($this->super_sales_group_profit), 'pay_type' => intval($this->pay_type), 'bank' => intval($this->bank), 'lg' => intval($this->lg), 'remaining_sum' => intval($this->remaining_sum), 'cash_service_charge' => floatval($this->cash_service_charge), 'min_money' => floatval($this->min_money), 'cash_max_single_day' => floatval($this->cash_max_single_day), 'cash_max_day' => floatval($this->cash_max_day), 'goods_ids' => $this->goods_ids, 'cash_price_type' => $this->cash_price_type ?? '1', 'cash_price_amount' => $this->cash_price_amount ?? 100, 'cash_price_integral' => $this->cash_price_integral ?? 0, 'cash_price_balance' => $this->cash_price_balance ?? 0, 'upgrade_direct_profit' => $this->upgrade_direct_profit ?? 0, 'super_sales_bg' => $this->super_sales_bg ?? '' ]; // $total_profit = 0; // $cash_price_type = explode(',', $this->cash_price_type); // if (in_array(CashExt::CASH_PRICE_TYPE_AMOUNT, $cash_price_type)) { // $total_profit = bcadd($total_profit, $this->cash_price_amount, 2); // } // if (in_array(CashExt::CASH_PRICE_TYPE_INTEGRAL, $cash_price_type)) { // $total_profit = bcadd($total_profit, $this->cash_price_integral, 2); // } // if (in_array(CashExt::CASH_PRICE_TYPE_BALANCE, $cash_price_type)) { // $total_profit = bcadd($total_profit, $this->cash_price_balance, 2); // } // if ($total_profit != 100) { // return [ // 'code' => 1, // 'msg' => '佣金/积分/余额比例设置错误' // ]; // } $goods_ids = explode(',', $data['goods_ids'] ?? ''); if (empty($goods_ids)) { throw new \Exception('请选择商品'); } foreach ($goods_ids as $goods_id) { $goods = Goods::findOne(['id' => $goods_id, 'is_delete' => 0, 'store_id' => $store_id]); if (!$goods) { throw new \Exception('商品信息错误' . $goods_id); } } Option::set('super_sales_setting', json_encode($data), $store_id, 'super_sales'); return [ 'code' => 0, 'msg' => '保存成功' ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } }