| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- <?php
- namespace app\modules\admin\models\superSales;
- use app\models\CashExt;
- use app\models\Cat;
- use app\models\Goods;
- use app\models\GoodsCat;
- use app\models\Option;
- use yii\base\Model;
- class SettingForm extends Model
- {
- public $store_id;
- public $super_sales_direct_profit;
- public $super_sales_group_profit;
- public $pay_type;
- public $bank;
- public $lg;
- public $remaining_sum;
- public $cash_service_charge;
- public $min_money;
- public $cash_max_single_day;
- public $cash_max_day;
- public $goods_ids;
- public $cash_price_amount;
- public $cash_price_integral;
- public $cash_price_balance;
- public $cash_price_type;
- public $super_sales_bg;
- //立即升级
- public $upgrade_direct_profit;
- public function rules()
- {
- return [
- [['store_id', 'pay_type', 'bank', 'remaining_sum', 'upgrade_direct_profit'], 'integer'],
- [['super_sales_direct_profit', 'super_sales_group_profit', 'cash_service_charge',
- 'min_money', 'cash_max_single_day', 'cash_max_day', 'cash_price_amount', 'cash_price_integral', 'cash_price_balance'], 'number'],
- [['goods_ids', 'cash_price_type', 'super_sales_bg'], 'string'],
- [['bank', 'remaining_sum', 'lg'], 'in', 'range' => [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()
- ];
- }
- }
- }
|