diff --git a/app/common/dao/store/coupon/StoreCouponUserDao.php b/app/common/dao/store/coupon/StoreCouponUserDao.php index 35f3293d..974f1807 100644 --- a/app/common/dao/store/coupon/StoreCouponUserDao.php +++ b/app/common/dao/store/coupon/StoreCouponUserDao.php @@ -19,6 +19,7 @@ use app\common\model\BaseModel; use app\common\model\store\coupon\StoreCouponDetail; use app\common\model\store\coupon\StoreCouponUser; use app\common\repositories\store\coupon\StoreCouponRepository; +use app\common\repositories\store\coupon\StoreCouponUserRepository; use think\exception\ValidateException; /** @@ -294,4 +295,42 @@ class StoreCouponUserDao extends BaseDao } } + public function totalAmount($userId) + { + $totalAmount = StoreCouponUser::where('uid', $userId) + ->whereIn('coupon_type', [StoreCouponRepository::TYPE_STORE_COUPON, StoreCouponRepository::TYPE_PLATFORM_CARD]) + ->where('status', StoreCouponUserRepository::STATUS_UNUSED) + ->field('SUM(coupon_price) as total_amount,coupon_type') + ->group('coupon_type') + ->select()->toArray(); + $totalAmount = reset_index($totalAmount, 'coupon_type'); + $result = [ + [ + 'coupon_type' => 1, + 'total_amount' => 0.00 + ], + [ + 'coupon_type' => 2, + 'total_amount' => 0.00 + ] + ]; + foreach ($result as &$item) { + if (isset($totalAmount[$item['coupon_type']])) { + $item['total_amount'] = $totalAmount[$item['coupon_type']]['total_amount']; + } + $item['type_cn'] = StoreCouponRepository::TYPE_MAP[$item['coupon_type']]; + } + return $result; + } + + public function record($userId, $type, $page, $limit) + { + + } + + public function useRecord($userId, $type, $page, $limit) + { + + } + } diff --git a/app/common/repositories/store/coupon/StoreCouponRepository.php b/app/common/repositories/store/coupon/StoreCouponRepository.php index af2e999e..acad5beb 100644 --- a/app/common/repositories/store/coupon/StoreCouponRepository.php +++ b/app/common/repositories/store/coupon/StoreCouponRepository.php @@ -58,6 +58,10 @@ class StoreCouponRepository extends BaseRepository const TYPE_PLATFORM_STORE = 12; //平台购物卡,可全额抵扣,可结余 const TYPE_PLATFORM_CARD = 13; + const TYPE_MAP = [ + self::TYPE_STORE_COUPON => '春耕采购余额', + self::TYPE_PLATFORM_CARD => '补贴', + ]; //获取方式 const GET_COUPON_TYPE_RECEIVE = 0; diff --git a/app/controller/admin/system/merchant/Merchant.php b/app/controller/admin/system/merchant/Merchant.php index 1fcd6ecc..84877688 100644 --- a/app/controller/admin/system/merchant/Merchant.php +++ b/app/controller/admin/system/merchant/Merchant.php @@ -206,7 +206,7 @@ class Merchant extends BaseController */ public function checkParam(MerchantValidate $validate, $isUpdate = false) { - $data = $this->request->params([['category_id', 0], ['type_id', 0], 'mer_name', 'commission_rate', 'real_name', 'mer_phone', 'mer_keyword', 'mer_address', 'mark', ['sort', 0], ['status', 0], ['is_audit', 0], ['is_best', 0], ['is_bro_goods', 0], ['is_bro_room', 0], ['is_trader', 0], 'sub_mchid', ['commission_switch', 0]]); + $data = $this->request->params([['category_id', 0], ['type_id', 0], 'mer_name', 'commission_rate', 'real_name', 'mer_phone', 'mer_keyword', 'mer_address', 'mark', ['sort', 0], ['status', 0], ['is_audit', 0], ['is_best', 0], ['is_bro_goods', 0], ['is_bro_room', 0], ['is_trader', 0], 'sub_mchid', ['commission_switch', 0], 'city_id', 'area_id', 'street_id', 'village_id','sub_mchid', 'auto_margin_rate', 'margin']); if (!$isUpdate) { $data += $this->request->params(['mer_account', 'mer_password']); } else { diff --git a/app/controller/admin/system/merchant/MerchantType.php b/app/controller/admin/system/merchant/MerchantType.php index 5af3944a..87d6dd37 100644 --- a/app/controller/admin/system/merchant/MerchantType.php +++ b/app/controller/admin/system/merchant/MerchantType.php @@ -94,7 +94,7 @@ class MerchantType extends BaseController protected function getValidParams() { - $data = $this->request->params(['type_name', 'type_info', 'is_margin', 'margin', 'auth', 'description', 'mark']); + $data = $this->request->params(['type_name', 'type_info', 'is_margin', 'margin', 'auth', 'description', 'mark', 'is_allow_apply', 'is_search_display']); $validate = app()->make(MerchantTypeValidate::class); $validate->check($data); if ($data['is_margin'] == 1) { diff --git a/app/controller/api/store/StoreActivity.php b/app/controller/api/store/StoreActivity.php new file mode 100644 index 00000000..482381db --- /dev/null +++ b/app/controller/api/store/StoreActivity.php @@ -0,0 +1,59 @@ +request->uid(); + $type = $this->request->get('type', 1); + $page = $this->request->get('page', 1); + $limit = $this->request->get('limit', 10); + $result = $dao->record($userId, $type, $page, $limit); + return app('json')->success($result); + } + + /** + * 红包余额统计 + * @param StoreCouponUserDao $dao + * @return mixed + */ + public function total(StoreCouponUserDao $dao) + { + $userId = $this->request->uid(); + $result = $dao->totalAmount($userId); + return app('json')->success($result); + } + + /** + * 红包使用记录 + * @param StoreCouponUserDao $dao + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function useRecord(StoreCouponUserDao $dao) + { + $userId = $this->request->uid(); + $type = $this->request->get('type', 1); + $page = $this->request->get('page', 1); + $limit = $this->request->get('limit', 10); + $result = $dao->useRecord($userId, $type, $page, $limit); + return app('json')->success($result); + } + +} diff --git a/app/controller/api/store/merchant/Merchant.php b/app/controller/api/store/merchant/Merchant.php index 89d06cbc..a7fba407 100644 --- a/app/controller/api/store/merchant/Merchant.php +++ b/app/controller/api/store/merchant/Merchant.php @@ -13,7 +13,11 @@ namespace app\controller\api\store\merchant; use app\common\model\system\merchant\MerchantType; +use app\common\repositories\system\financial\FinancialRepository; +use app\common\repositories\system\merchant\MerchantRepository; +use app\common\repositories\user\UserBillRepository; use app\common\repositories\user\UserMerchantRepository; +use app\validate\merchant\MerchantFinancialAccountValidate; use think\App; use crmeb\basic\BaseController; use app\common\repositories\system\merchant\MerchantRepository as repository; @@ -130,4 +134,107 @@ class Merchant extends BaseController return app('json')->success($this->repository->getList($where, $page, $limit, $this->userInfo)); } + public function apply($merId) + { + $merchant = app()->make(MerchantRepository::class)->search(['mer_id' => $merId])->field('uid,mer_id,mer_name,mer_money,financial_bank,financial_wechat,financial_alipay,financial_type,ot_margin')->find(); + if (($msg = $this->checkAuth($merchant)) !== true) { + return app('json')->fail($msg); + } + $extract_minimum_line = systemConfig('extract_minimum_line') ?: 0; + $extract_minimum_num = systemConfig('extract_minimum_num'); + $_line = bcsub($merchant->mer_money, $extract_minimum_line, 2); + $_extract = ($_line < 0) ? 0 : $_line; + $merLockMoney = app()->make(UserBillRepository::class)->merchantLickMoney($merId); + $data = [ + 'mer_id' => $merchant->mer_id, //商户id + 'mer_name' => $merchant->mer_name, //商户名称 + 'mer_money' => $merchant->mer_money, //商户余额 + 'lock_money' => $merLockMoney, //冻结金额 + 'lock_time' => systemConfig('mer_lock_time'), //冻结金额 + 'extract_minimum_line' => $extract_minimum_line, //提现最低额度 + 'extract_minimum_num' => $extract_minimum_num, //提现最低次数 + 'extract_money' => $_extract, //可提现金额 + 'financial_bank_name' => $merchant->financial_bank->name ?? '', //银行账户姓名 + 'financial_bank_bank' => $merchant->financial_bank->bank ?? '', //开户行 + 'financial_bank_code' => $merchant->financial_bank->bank_code ?? '', //银行账号 + 'financial_bank_branch' => $merchant->financial_bank->bank_branch ?? '', //开户行地址 + 'financial_type' => $merchant->financial_type, //提现方式 + 'ot_margin' => $merchant->ot_margin, //提现方式 + + ]; + return app('json')->success($data); + } + + public function createApply($merId) + { + $data = $this->request->param(['extract_money', 'financial_type', 'financial_bank_name', 'financial_bank_bank', 'financial_bank_code', 'financial_bank_branch']); + $merchant = app()->make(MerchantRepository::class)->search(['mer_id' => $merId])->field('reg_admin_id,uid,mer_id,mer_name,mer_money,financial_bank,financial_wechat,financial_alipay,financial_type')->find(); + if (($msg = $this->checkAuth($merchant)) !== true) { + return app('json')->fail($msg); + } + $bankInfo = [ + 'name' => $data['financial_bank_name'], + 'bank' => $data['financial_bank_bank'], + 'bank_code' => $data['financial_bank_code'], + 'bank_branch' => $data['financial_bank_branch'], + ]; + $merchant->update(['financial_bank' => json_encode($bankInfo, JSON_UNESCAPED_UNICODE)], ['mer_id' => $merId]); + $data['mer_admin_id'] = $merchant['reg_admin_id']; + unset($data['financial_bank_name'], $data['financial_bank_bank'], $data['financial_bank_code'], $data['financial_bank_branch']); + app()->make(FinancialRepository::class)->saveApply($merId, $data); + return app('json')->success('申请成功'); + } + + public function listApply($merId) + { + $merchant = app()->make(MerchantRepository::class)->search(['mer_id' => $merId])->field('reg_admin_id,uid,mer_id,mer_name,mer_money,financial_bank,financial_wechat,financial_alipay,financial_type')->find(); + if (($msg = $this->checkAuth($merchant)) !== true) { + return app('json')->fail($msg); + } + [$page, $limit] = $this->getPage(); + $where['mer_id'] = $merId; + $data = app()->make(FinancialRepository::class)->getAdminList($where, $page, $limit); + return app('json')->success($data); + } + + public function account($merId) + { + $merchant = app()->make(MerchantRepository::class)->search(['mer_id' => $merId])->field('uid,mer_id,mer_name,mer_money,financial_bank,financial_wechat,financial_alipay,financial_type')->find(); + if (($msg = $this->checkAuth($merchant)) !== true) { + return app('json')->fail($msg); + } + $data = [ + 'financial_bank' => $merchant->financial_bank, //银行卡信息 + 'financial_wechat' => $merchant->financial_wechat, //微信信息 + 'financial_alipay' => $merchant->financial_alipay, //支付宝信息 + 'financial_type' => $merchant->financial_type, //提现方式 + ]; + return app('json')->success($data); + } + + public function account_info($merId) + { + $data = $this->request->param(['name', 'bank', 'bank_code', 'financial_type']); + app()->make(MerchantFinancialAccountValidate::class)->check($data); + $merchant = app()->make(MerchantRepository::class)->search(['mer_id' => $merId])->field('uid,mer_id,mer_name,mer_money,financial_bank,financial_wechat,financial_alipay,financial_type')->find(); + if (($msg = $this->checkAuth($merchant)) !== true) { + return app('json')->fail($msg); + } + $update = [ + 'name' => $data['name'], + 'bank' => $data['bank'], + 'bank_code' => $data['bank_code'], + ]; + app()->make(MerchantRepository::class)->update($merId, ['financial_bank' => json_encode($update), 'financial_type' => 1]); + return app('json')->success('提交成功'); + } + + public function checkAuth($merchant) + { + if ($this->userInfo['uid'] != $merchant->uid) { + return '你不是管理员无法进行提现操作'; + } + return true; + } + } diff --git a/route/api.php b/route/api.php index 645c5fa0..3e3fd6c1 100644 --- a/route/api.php +++ b/route/api.php @@ -247,6 +247,12 @@ Route::group('api/', function () { Route::post('store/product/group/cancel', 'api.store.product.StoreProductGroup/cancel'); Route::get('admin/:merId/expenditure', 'api.server.StoreOrder/expenditure');//商户账单 + //管理员申请转账 + Route::get('admin/:merId/apply', 'api.store.merchant.Merchant/apply'); + Route::post('admin/:merId/create_apply', 'api.store.merchant.Merchant/createApply'); + Route::get('admin/:merId/lis_apply', 'api.store.merchant.Merchant/listApply'); + Route::get('admin/:merId/account_apply', 'api.store.merchant.Merchant/account'); + Route::post('admin/:merId/account_apply', 'api.store.merchant.Merchant/account_info'); //客服商品管理 Route::group('server/:merId', function () { //商品 @@ -598,6 +604,12 @@ Route::group('api/', function () { Route::get('/info/:form_id', '/getFormInfo'); Route::get('/share_posters/:id', '/getSharePosters'); })->prefix('api.store.form.Form'); + //拉新红包活动 + Route::group('storeActivity', function () { + Route::get('record', 'api.store.StoreActivity/record'); //活动红包获取记录 + Route::get('total', 'api.store.StoreActivity/total'); //活动红包统计 + Route::get('useRecord', 'api.store.StoreActivity/useRecord'); //活动红包使用记录 + }); })->middleware(UserTokenMiddleware::class, false);