type; // $rule_id = $this->rule_id; $name = $this->name; $query = Store::find()->alias('s')->leftJoin(['a' => Admin::tableName()], 's.admin_id = a.id')->where(['s.is_delete' => 0, 'a.is_delete' => 0])->select('s.id, s.name, s.logo'); $store_ids = []; //排除store_id // if ($rule_id) { // if ((int)$type === 0 || empty($type)) { // $store_ids = RulesFaceStore::find()->where(['rule_id' => $rule_id])->select('store_id')->column(); // } // if ((int)$type === 1) { // $store_ids = RulesGiveIntegralStore::find()->where(['rule_id' => $rule_id])->select('store_id')->column(); // } // } if ($name) { $query->andWhere(['like' ,'s.name', $name]); } $query->andWhere(['not in', 's.id', $store_ids]); // $pagination = pagination_make($query); // $list = $pagination['list']; $list = $query->asArray()->all(); return [ 'code' => 0, 'data' => [ 'list' => $list, // 'pageNo' => $pagination['pageNo'], // 'totalCount' => $pagination['totalCount'] ] ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } public function getRulesList() { try { $status = $this->status; $name = $this->name; $end_date = strtotime($this->end_date); $start_date = strtotime($this->start_date); $query_main = GiveIntegralRules::find()->where(['is_delete' => 0]); if (in_array($status, [1, 2])) { $query_main->andWhere(['status' => $status]); } if ($start_date) { $query_main->andWhere(['>=', 'start_date', $start_date]); } if ($end_date) { $query_main->andWhere(['<=', 'end_date', $end_date]); } $pagination = pagination_make($query_main); $list = $pagination['list']; foreach ($list as $index => &$item) { $open = false; $item['faceStore'] = RulesFaceStore::find()->where(['fs.rule_id' => $item['id']])->alias('fs') ->leftJoin(['s' => Store::tableName()], 'fs.store_id = s.id') ->select('s.id, s.name, s.logo, fs.rule_id')->asArray()->all(); foreach ($item['faceStore'] as &$face_item) { if (!empty($name) && ($face_item['name'] !== $name)) { $open = true; } } $item['giveIntegralStore'] = RulesGiveIntegralStore::find()->where(['gis.rule_id' => $item['id']]) ->alias('gis')->leftJoin(['s' => Store::tableName()], 'gis.store_id = s.id') ->select('s.id, s.name, s.logo, gis.rule_id')->asArray()->all(); $item['created_at'] = date("Y-m-d H:i", $item['created_at']); $item['start_date'] = date("Y-m-d H:i:s", $item['start_date']); $item['end_date'] = date("Y-m-d H:i:s", $item['end_date']); if ($open) { unset($list[$index]); } } return [ 'code' => 0, 'msg' => 'success', 'data' => [ 'data' => $list, 'pageNo' => $pagination['pageNo'], 'totalCount' => $pagination['totalCount'] ] ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } public function getInfo() { try { $rule_id = $this->rule_id; $rules = GiveIntegralRules::find()->where(['id' => $rule_id, 'is_delete' => 0])->with([ 'faceStore' => function ($query) { $query->alias('fs')->leftJoin(['s' => Store::tableName()], 'fs.store_id = s.id')->select('s.id, s.name, s.logo, fs.rule_id')->asArray(); }, 'giveIntegralStore' => function ($query) { $query->alias('gis')->leftJoin(['s' => Store::tableName()], 'gis.store_id = s.id')->select('s.id, s.name, s.logo, gis.rule_id')->asArray(); }, ])->asArray()->one(); $rules['created_at'] = date("Y-m-d H:i", $rules['created_at']); $rules['start_date'] = date("Y-m-d H:i:s", $rules['start_date']); $rules['end_date'] = date("Y-m-d H:i:s", $rules['end_date']); return [ 'code' => 0, 'msg' => 'success', 'data' => $rules ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } public function save() { try { $rule_id = $this->rule_id; $face_pay_ids = explode(',', $this->face_pay_ids); $give_integral_ids = explode(',', $this->give_integral_ids); $rules = GiveIntegralRules::findOne(['id' => $rule_id, 'is_delete' => 0]); if (!$rule_id) { $rules = new GiveIntegralRules(); $rules->created_at = time(); } $rules->rate = $this->rate; $rules->start_date = strtotime($this->start_date); $rules->end_date = strtotime($this->end_date); if (!in_array((int)$this->status, [1, 2])) { throw new \Exception("状态错误"); } $rules->status = $this->status; if (!$rules->save()) { throw new \Exception(json_encode($rules->errors)); } $rule_id = $rules->id; RulesFaceStore::deleteAll(['rule_id' => $rule_id]); RulesGiveIntegralStore::deleteAll(['rule_id' => $rule_id]); foreach ($face_pay_ids as $item) { $form = new RulesFaceStore(); $form->store_id = $item; $form->rule_id = $rule_id; $form->created_at = time(); if (!$form->save()) { throw new \Exception(json_encode($form->errors)); } } foreach ($give_integral_ids as $item) { $form = new RulesGiveIntegralStore(); $form->store_id = $item; $form->rule_id = $rule_id; $form->created_at = time(); $form->save(); if (!$form->save()) { throw new \Exception(json_encode($form->errors)); } } return [ 'code' => 0, 'msg' => "保存成功" ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } public function setStatus() { try { $rule_id = $this->rule_id; if (!is_string($rule_id)) { throw new \Exception("数据格式错误"); } $rule_id = explode(',', $rule_id); $status = (int)$this->status; $rules = GiveIntegralRules::find()->where(['id' => $rule_id, 'is_delete' => 0])->all(); if (!$rules) { throw new \Exception("获取数据失败"); } foreach ($rules as $item) { if (in_array($status, [1, 2])) { $item->status = $status; } elseif ($status === 3) { $item->is_delete = 1; } if (!$item->save()) { throw new \Exception(json_encode($item->errors)); } } return [ 'code' => 0, 'msg' => "操作成功" ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage() ]; } } public static function yunstSetting($is_saas = 0, $store_id = 0, $refresh = 0){ if(self::$bankSetting && !$refresh){ $oldConf = self::$bankSetting; }else{ $oldConf = Option::get(OptionSetting::SAAS_YUNST_SETTING, 0, 'saas')['value']; self::$bankSetting = $oldConf; } $oldConf && $oldConf = json_decode($oldConf, true); return $oldConf ?: null; } public static function yunstSettingSave($is_saas = 0, $store_id = 0, $conf = []){ if(empty($conf)){ return false; } // print_r($conf);die; $oldConf = json_decode(Option::get(OptionSetting::SAAS_YUNST_SETTING, 0, 'saas', '{}')['value'], true); $conf = array_merge($oldConf, $conf); $set = Option::set(OptionSetting::SAAS_YUNST_SETTING, json_encode($conf), 0, 'saas'); self::yunstSetting($is_saas, $store_id, 1); return $set; } public static function bankSetting($is_saas = 0, $store_id = 0, $refresh = 0){ if($is_saas){ if(self::$bankSetting && !$refresh){ $oldConf = self::$bankSetting; }else{ $oldConf = Option::get(OptionSetting::SAAS_BANK_SETTING, 0, 'saas')['value']; self::$bankSetting = $oldConf; } }elseif($store_id){ if(self::$bankSettingStore[$store_id] && !$refresh){ $oldConf = self::$bankSettingStore[$store_id]; }else{ $oldConf = Option::get(OptionSetting::STORE_BANK_SETTING, $store_id, 'saas')['value']; self::$bankSettingStore[$store_id] = $oldConf; } } $oldConf && $oldConf = json_decode($oldConf, true); return $oldConf ?: null; } public static function bankSettingSave($is_saas = 0, $store_id = 0, $conf = []){ /** * card_id 银行卡号 card_name 银行卡对应的户名 cert_id 证件号,银行账户类型为对私时,必填 cert_type 证件类型,仅支持:00-身份证,银行账户类型为对私时,必填 tel_no 手机号 bank_code 银行编码,详见附录 银行代码,银行账户类型对公时,必填 bank_name 开户银行名称 bank_acct_type 银行账户类型:1-对公;2-对私 prov_code 银行账户开户银行所在省份编码 (省市编码),银行账户类型为对公时,必填 area_code 银行账户开户银行所在地区编码(省市编码),银行账户类型为对公时,必填 */ if(empty($conf)){ return false; } if($is_saas){ $oldConf = json_decode(Option::get(OptionSetting::SAAS_BANK_SETTING, 0, 'saas', '{}')['value'], true); $conf = array_merge($oldConf, $conf); $set = Option::set(OptionSetting::SAAS_BANK_SETTING, json_encode($conf), 0, 'saas'); }elseif($store_id){ $oldConf = json_decode(Option::get(OptionSetting::STORE_BANK_SETTING, $store_id, 'saas', '{}')['value'], true); $conf = array_merge($oldConf, $conf); $set = Option::set(OptionSetting::STORE_BANK_SETTING, json_encode($conf), $store_id, 'saas'); } self::bankSetting($is_saas, $store_id, 1); return $set; } public static function bankSettingGet($is_saas, $store_id, $key){ $oldConf = self::bankSetting($is_saas, $store_id); if(empty($oldConf)){ return null; } return $oldConf[$key] ?? null; } public static function offlineSetting($store_id = 0, $refresh = 0){ if(self::$offlineSetting[$store_id] && !$refresh){ $oldConf = self::$offlineSetting[$store_id]; }else{ $oldConf = Option::get(OptionSetting::STORE_PAY_OFFLINE, $store_id, 'saas')['value']; self::$offlineSetting[$store_id] = $oldConf; } $oldConf && $oldConf = json_decode($oldConf, true); return $oldConf ?: [ // 'open_bank' => '0', //是否开启银行卡支付 'open_alipay' => '0', //是否开启支付宝支付 'open_wechat' => '0', //是否开启微信支付 // 'bank_name' => '', //开户银行名称 'bank_branch_name' => '', //开户银行支行名称 'bank_card_id' => '', //银行卡号 'bank_card_name' => '', //银行卡对应的户名 'alipay_qrcode' => '', //支付宝收款二维码 'wechat_qrcode' => '', //微信收款二维码 ]; } public static function offlineSettingSave($store_id = 0, $conf = []){ /** * open_bank 是否开启银行卡支付 open_alipay 是否开启支付宝支付 open_wechat 是否开启微信支付 * bank_name 开户银行名称 bank_branch_name 开户银行支行名称 bank_card_id 银行卡号 bank_card_name 银行卡对应的户名 alipay_qrcode 支付宝收款二维码 wechat_qrcode 微信收款二维码 */ if(empty($conf)){ return false; } $oldConf = json_decode(Option::get(OptionSetting::STORE_PAY_OFFLINE, $store_id, 'saas', '{}')['value'], true); $conf = array_merge($oldConf, $conf); $set = Option::set(OptionSetting::STORE_PAY_OFFLINE, json_encode($conf), $store_id, 'saas'); self::offlineSetting($store_id, 1); return $set; } public static function offlineSettingGet($store_id, $key){ $oldConf = self::offlineSetting($store_id); if(empty($oldConf)){ return null; } return $oldConf[$key] ?? null; } }