diff --git a/app/common.php b/app/common.php index 0c64202..24bedbf 100644 --- a/app/common.php +++ b/app/common.php @@ -1272,3 +1272,60 @@ if (!function_exists('create_form')) { return compact('rules', 'title', 'action', 'method', 'info', 'status'); } } +if (!function_exists('getFirstCharter')) { + function getFirstCharter($str){ + if(empty($str)) return ''; + $strArr = preg_split('//u', $str, -1, PREG_SPLIT_NO_EMPTY); + $pingYin = []; + for($i=0;$i= ord('A') && $fchar <= ord('z')) { + $pingYin[] = strtoupper($text); //如果是字母则返回字母的大写 + continue; + } + $s1 = iconv('UTF-8','gb2312',$text); + $s2 = iconv('gb2312','UTF-8',$s1); + $s = $s2 == $text ? $s1 : $text; + $asc = ord($s[0]) * 256 + ord($s[1]) - 65536; + if($asc >= -20319 && $asc <= -20284) $pingYin[] = 'A';//这些都是汉字 + if($asc >= -20283 && $asc <= -19776) $pingYin[] = 'B'; + if($asc >= -19775 && $asc <= -19219) $pingYin[] = 'C'; + if($asc >= -19218 && $asc <= -18711) $pingYin[] = 'D'; + if($asc >= -18710 && $asc <= -18527) $pingYin[] = 'E'; + if($asc >= -18526 && $asc <= -18240) $pingYin[] = 'F'; + if($asc >= -18239 && $asc <= -17923) $pingYin[] = 'G'; + if($asc >= -17922 && $asc <= -17418) $pingYin[] = 'H'; + if($asc >= -17417 && $asc <= -16475) $pingYin[] = 'J'; + if($asc >= -16474 && $asc <= -16213) $pingYin[] = 'K'; + if($asc >= -16212 && $asc <= -15641) $pingYin[] = 'L'; + if($asc >= -15640 && $asc <= -15166) $pingYin[] = 'M'; + if($asc >= -15165 && $asc <= -14923) $pingYin[] = 'N'; + if($asc >= -14922 && $asc <= -14915) $pingYin[] = 'O'; + if($asc >= -14914 && $asc <= -14631) $pingYin[] = 'P'; + if($asc >= -14630 && $asc <= -14150) $pingYin[] = 'Q'; + if($asc >= -14149 && $asc <= -14091) $pingYin[] = 'R'; + if($asc >= -14090 && $asc <= -13319) $pingYin[] = 'S'; + if($asc >= -13318 && $asc <= -12839) $pingYin[] = 'T'; + if($asc >= -12838 && $asc <= -12557) $pingYin[] = 'W'; + if($asc >= -12556 && $asc <= -11848) $pingYin[] = 'X'; + if($asc >= -11847 && $asc <= -11056) $pingYin[] = 'Y'; + if($asc >= -11055 && $asc <= -10247) $pingYin[] = 'Z'; + } + + return implode($pingYin); + } +} + + + + + + + + + diff --git a/app/common/dao/user/VipExchangeCodeDao.php b/app/common/dao/user/VipExchangeCodeDao.php new file mode 100644 index 0000000..87e3c22 --- /dev/null +++ b/app/common/dao/user/VipExchangeCodeDao.php @@ -0,0 +1,51 @@ +when(isset($params['id']) && $params['id'] !== '',function($query) use ($params){ + $query->where('id', (int)$params['id']); + }) + ->when(isset($params['batch_title']) && $params['batch_title'] !== '',function($query) use ($params){ + $query->where('batch_title', $params['batch_title']); + }) + ->when(isset($params['batch_unique']) && $params['batch_unique'] !== '',function($query) use ($params){ + $query->where('batch_unique', $params['batch_unique']); + }) + ->when(isset($params['exchange_code']) && $params['exchange_code'] !== '',function($query) use ($params){ + $query->where('exchange_code', $params['exchange_code']); + }) + ->when(isset($params['status']) && $params['status'] !== '',function($query) use ($params){ + $query->where('status', (int)$params['status']); + }) + ->when(isset($params['mer_id']) && $params['mer_id'] !== '',function($query) use ($params){ + $query->where('mer_id', (int)$params['mer_id']); + }) + ->when(isset($params['group_data_id']) && $params['group_data_id'] !== '',function($query) use ($params){ + $query->where('group_data_id', (int)$params['group_data_id']); + }) + // ->with() + ->order('create_time DESC,id DESC'); + } + + + + + +} diff --git a/app/common/model/user/UserVipExchangeCode.php b/app/common/model/user/UserVipExchangeCode.php new file mode 100644 index 0000000..b9775bb --- /dev/null +++ b/app/common/model/user/UserVipExchangeCode.php @@ -0,0 +1,25 @@ +dao = $dao; + } + /** + * Common: 公共查询模型 + * Author: wu-hui + * Time: 2024/03/02 14:17 + * @param $search + * @return \app\common\model\user\UserVipExchangeCode + */ + public function getSearchModel($search){ + return $this->dao->searchList($search); + } + /** + * Common: 获取信息列表 + * Author: wu-hui + * Time: 2024/03/02 14:18 + * @param array $params + * @param int $page + * @param int $limit + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getList(array $params,int $page,int $limit):array{ + $query = $this->dao->searchList($params); + $count = $query->count(); + $list = $query->page($page,$limit)->select()->toArray(); + + return compact('count','list'); + } + /** + * Common: 生成创建表单数据 + * Author: wu-hui + * Time: 2024/03/02 11:38 + * @return \FormBuilder\Form + * @throws \FormBuilder\Exception\FormBuilderException + */ + public function getEditFormData():\FormBuilder\Form{ + $formData = []; + $url = Route::buildUrl('systemUserVipExchangeCodeEditInfo')->build(); + $form = Elm::createForm($url); + $rules = [ + Elm::input('batch_title','当前批次名称')->required()->col(16), + Elm::input('create_num','生成数量')->required()->col(16) + ->type('number') + ->min('1') + ->max('999999') + ->step('1'), + ]; + $form->setRule($rules); + return $form->setTitle( '添加兑换码')->formData($formData); + } + /** + * Common: 兑换码生成 + * Author: wu-hui + * Time: 2024/03/02 13:52 + * @param $params + * @return int + */ + public function createExchangeCode($params){ + // 是否允许生成兑换码 + if($params['create_num'] <= 0) throw new ValidateException('生成数量必须大于0'); + $isHas = (int)$this->dao->getSearch(['batch_title'=>$params['batch_title']])->value('id'); + if($isHas > 0) throw new ValidateException('名称已经存在,请更换名称!'); + // 生成操作 + $initial = substr(getFirstCharter($params['batch_title']), 0, 1); + $batchUnique = strtoupper(uniqid($initial));// 批次唯一编号 + $insertData = []; + for($i = 0; count($insertData) < $params['create_num']; $i++){ + // 兑换码生成 + $exchangeCode = strtoupper($initial . substr(uniqid(), -8)); + if(!in_array($exchangeCode, array_column($insertData,'exchange_code'))){ + $insertData[] = [ + 'batch_title' => $params['batch_title'], + 'batch_unique' => $batchUnique, + 'exchange_code' => strtoupper($initial . substr(uniqid(), -8)), + ]; + } + } + + return $this->dao->insertAll($insertData); + } + + + +} diff --git a/app/controller/admin/user/ExchangeCode.php b/app/controller/admin/user/ExchangeCode.php new file mode 100644 index 0000000..0c36acc --- /dev/null +++ b/app/controller/admin/user/ExchangeCode.php @@ -0,0 +1,97 @@ +repository = $repository; + } + /** + * Common: 兑换码列表 + * Author: wu-hui + * Time: 2024/03/02 14:21 + * @return mixed + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getList(){ + [$page, $limit] = $this->getPage(); + $params = $this->request->params(['is_export','batch_unique','status']); + $data = $this->repository->getList((array)$params,(int)$page,(int)$limit); + // 导出数据处理 + if($params['is_export'] == 1){ + // 处理其他导出信息 + $data['title'] = [ + '兑换码', + '生成时间:' . date('Y-m-d H:i:s',time()) + ]; + $data['header'] = ['批次名称','批次编号','兑换码', '小程序链接']; + $data['filename'] = '兑换码_'.time(); + // 处理跳转路径 + $data['list'] = array_map(function($item){ + $path = '/pages/annex/vip_center/index?ec='.$item['exchange_code']; + return [ + $item['batch_title'] ?? '', + $item['batch_unique'] ?? '', + $item['exchange_code'], + $path, + ]; + }, $data['list']); + $data['list'] = array_reverse($data['list']); + } + + return app('json')->success($data); + } + /** + * Common: 获取批次列表 + * Author: wu-hui + * Time: 2024/03/02 14:45 + * @return mixed + */ + public function getBatchList(){ + $list = $this->repository->getSearchModel([])->column('batch_unique','batch_title'); + + return app('json')->success($list); + } + /** + * Common: 兑换码编辑表单 + * Author: wu-hui + * Time: 2024/03/02 11:39 + * @return mixed + * @throws \FormBuilder\Exception\FormBuilderException + */ + public function editForm(){ + $data = $this->repository->getEditFormData(); + + return app('json')->success(formToData($data)); + } + /** + * Common: 兑换码编辑提交信息 + * Author: wu-hui + * Time: 2024/03/02 14:07 + * @return mixed + */ + public function editInfo(){ + $params = $this->request->params(['batch_title',['create_num', 0]]); + $this->repository->createExchangeCode($params); + + return app('json')->success(); + } + + + + + + + + +} diff --git a/route/admin/member.php b/route/admin/member.php index adf1972..a079fda 100644 --- a/route/admin/member.php +++ b/route/admin/member.php @@ -47,6 +47,24 @@ Route::group(function () { ], ] ]); + //付费会员等级 + Route::group('user/exchangeCode', function () { + // 兑换码列表 + Route::get('getList', 'admin.user.ExchangeCode/getList')->name('systemUserVipExchangeCodeGetList'); + // 兑换码批次列表 + Route::get('getBatchList', 'admin.user.ExchangeCode/getBatchList')->name('systemUserVipExchangeCodeGetBatchList'); + // 编辑表单 + Route::get('editForm', 'admin.user.ExchangeCode/editForm')->name('systemUserVipExchangeCodeEdit'); + // 提交编辑信息 + Route::post('editInfo', 'admin.user.ExchangeCode/editInfo')->name('systemUserVipExchangeCodeEditInfo'); + })->append(['type' => 1])->option([ + '_path' => '/user/member/exchangeCode', + '_auth' => true, + ]); + + + + // 会员订单列表 Route::get('user/svip/order_lst', 'admin.user.Svip/payList')->name('systemUserSvipPayLst')->option([ '_alias' => '列表', '_path' => '/user/member/record', @@ -88,8 +106,6 @@ Route::group(function () { ], ] ]); - - //普通会员等级 Route::group('user/member', function () { Route::get('lst', '.UserBrokerage/getLst')->name('systemUserMemberLst')->option([ @@ -140,7 +156,6 @@ Route::group(function () { ], ] ]); - //普通会员权益 Route::group('member/interests', function () { Route::get('lst', '.MemberInterests/getLst')->name('systemUserMemberInterestsLst')->option([ @@ -193,6 +208,7 @@ Route::group(function () { ]); + })->middleware(AllowOriginMiddleware::class) ->middleware(AdminTokenMiddleware::class, true) ->middleware(AdminAuthMiddleware::class) diff --git a/route/api.php b/route/api.php index db32ffd..427bfc7 100644 --- a/route/api.php +++ b/route/api.php @@ -417,11 +417,6 @@ Route::group('api/', function () { Route::post('cart_add','cartAdd');// 添加购物车 Route::post('cart_del','cartDel');// 删除购物车商品 - - - - - })->prefix('api.Supplier/')->middleware(ShopTokenMiddleware::class,TRUE); })->middleware(UserTokenMiddleware::class, true); //非强制登录