| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?php
- namespace addons\Store\api\modules\v1\controllers;
- use addons\Store\client\controllers\BaseController;
- use addons\Store\common\enums\StoreEnum;
- use addons\Store\common\models\Store;
- use addons\Store\common\services\MerchantReduceProfitService;
- use addons\Store\common\services\MerchantService;
- use api\controllers\OnAuthController;
- use common\enums\StatusEnum;
- use yii\helpers\Json;
- /**
- * 商户
- * @package addons\Store\client\controllers
- */
- class MerchantController extends OnAuthController
- {
- public $modelClass = '';
- /**
- * 不用进行登录验证的方法
- *
- * 例如: ['index', 'update', 'create', 'view', 'delete']
- * 默认全部需要验证
- *
- * @var array
- */
- protected $authOptional = [];
- protected $authStore = ['yin-dian','reduce-profit'];
- protected $store_id = 0;
- public function beforeAction($action)
- {
- parent::beforeAction($action);
- //检测门店身份
- if(in_array($action->id,$this->authStore)){
- $store = Store::find()
- ->where(['mall_id' => $this->mall_id, 'user_id' => $this->user_id, 'status' => StatusEnum::ENABLED])
- ->one();
- if (empty($store)) {
- \Yii::$app->response->data = ['code' => 1, 'msg' => '您非门店身份'];
- \Yii::$app->response->send();
- return;
- }
- $this->store_id = $store->id;
- }
- return $action;
- }
- /**
- * 商户号设置
- *
- * @return void
- */
- public function actionYinDian()
- {
- if ($this->request->isGet) {
- $service = new MerchantService(['mall_id' => $this->mall_id, 'store_id' => $this->store_id]);
- $tips = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'tips');
- return $this->success('获取成功', [
- 'setting' => $service->getSetting(),
- 'link' => $service->getSignLink(),
- 'link_tips' => $tips['link_tips'] ?? '此链接用作申请银典子商户号,子商户号用作接收用户贷款,请您务必进行账号申请;进行账号申请后,请将申请的商户编号填入下方,为确保交易无误,请确保填入的商户号无误!否则因为填写错误造成的损失将由您自行承担!',
- 'bank_account_tips' => $tips['bank_account_tips'] ?? '用于快速到账,银行卡账户账户必须是和商户编号对应的账号,如填写错误会导致无法快速到账'
- ]);
- }
- if ($this->request->isPost) {
- $setting = $this->request->post();
- // 数据校验
- $res = \Yii::$app->services->validate->validate($setting, [
- [['mcht_cd','bank_account', 'name', 'bank_account_type'], 'required'],
- [['bank_account_type'], 'integer'],
- ], [
- 'mcht_cd' => '商户号',
- 'bank_account' => '银行账户',
- 'name' => '账户名称',
- 'bank_account_type' => '账户类型',
- ]);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- $service = new MerchantService(['mall_id' => $this->mall_id, 'store_id' => $this->store_id]);
- return $service->setSetting($setting)
- ? $this->success('设置成功')
- : $this->error('保存失败');
- }
- }
- public function actionReduceProfit()
- {
- $service = new MerchantReduceProfitService();
- $setting = $service->profit($this->mall_id, $this->user_id, $this->store_id);
- if ($this->request->isGet) {
- return $this->success('获取成功', $setting);
- }
- if ($this->request->isPost) {
- $params = $this->request->post();
- // 数据校验
- $res = \Yii::$app->services->validate->validate($params, [
- [['new_rate'], 'required'],
- [['new_rate'], 'number'],
- ], [
- 'new_rate' => '让利百分比',
- ]);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- // 校验
- if ($params['new_rate'] < $setting['min'] || $params['new_rate'] > $setting['max']) {
- return $this->error("让利百分比必须在 {$setting['min']} - {$setting['max']} 之间");
- }
- $ret = $service->save($this->mall_id, $this->user_id, $this->store_id, $params['new_rate']);
- return is_string($ret) ? $this->error($ret) : $this->success('提交成功');
- }
- }
- }
|