大大的豆芽 2 kuukautta sitten
vanhempi
commit
160acd0a54

+ 20 - 0
app/adminapi/controller/v1/export/ExportExcel.php

@@ -21,6 +21,7 @@ use app\services\order\StoreOrderServices;
 use app\services\product\product\StoreProductServices;
 use app\services\system\store\SystemStoreServices;
 use app\services\user\member\MemberCardServices;
+use app\services\user\member\SecurityCodeRecordServices;
 use app\services\user\UserBillServices;
 use app\services\user\UserRechargeServices;
 use app\services\wechat\WechatUserServices;
@@ -64,6 +65,7 @@ class ExportExcel extends AuthController
             ['country', ''],
             ['province', ''],
             ['city', ''],
+            ['city_name', ''],
             ['user_time_type', ''],
             ['user_time', ''],
             ['sex', ''],
@@ -103,6 +105,24 @@ class ExportExcel extends AuthController
         return app('json')->success($this->service->exportOrderList($where));
     }
 
+    /**
+     * 防伪码导出
+     * @return mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function codeList()
+    {
+        $where = $this->request->getMore([
+            ['category_id', ""],
+            ['security_code', ""],
+            ['scan_uid', ""],
+            ['status', ""]
+        ]);
+        return app('json')->success($this->service->exportCodeList($where));
+    }
+
     /**
      * 发货订单列表导出
      * @return mixed

+ 1 - 0
app/adminapi/controller/v1/user/User.php

@@ -47,6 +47,7 @@ class User extends AuthController
             ['country', ''],
             ['province', ''],
             ['city', ''],
+            ['city_name', ''],
             ['user_time_type', ''],
             ['user_time', ''],
             ['sex', ''],

+ 15 - 0
app/adminapi/controller/v1/user/member/SecurityCodeRecord.php

@@ -84,6 +84,21 @@ class SecurityCodeRecord extends AuthController
         return app('json')->success($id ? 100001 : 100021);
     }
 
+    /**
+     * 删除
+     * @param $id
+     * @throws \Exception
+     */
+    public function delete()
+    {
+        list($id) = $this->request->getMore([
+            ['id', 0],
+        ], true);
+        if (!$id) return app('json')->fail(100100);
+        $this->services->delCode((int)$id);
+        return app('json')->success(100002);
+    }
+
         /**
      * 导入
      * @return \think\Response|void

+ 2 - 0
app/adminapi/route/export.php

@@ -40,6 +40,8 @@ Route::group('export', function () {
     Route::get('userPoint', 'v1.export.ExportExcel/userPoint')->option(['real_name' => '用户积分导出']);
     //用户充值
     Route::get('userRecharge', 'v1.export.ExportExcel/userRecharge')->option(['real_name' => '用户充值导出']);
+    //防伪码导出
+    Route::get('code_list', 'v1.export.ExportExcel/codeList')->option(['real_name' => '防伪码导出']);
 })->middleware([
     \app\http\middleware\AllowOriginMiddleware::class,
     \app\adminapi\middleware\AdminAuthTokenMiddleware::class,

+ 2 - 0
app/adminapi/route/user.php

@@ -186,6 +186,8 @@ Route::group('user', function () {
         Route::get('security_category/list', 'v1.user.member.SecurityCategory/list')->option(['real_name' => '防伪分类列表']);
         Route::get('security_category/set_value/:id', 'v1.user.member.SecurityCategory/set_value')->option(['real_name' => '分类状态更新']);
         Route::post('security_category/save/:id', 'v1.user.member.SecurityCategory/save')->option(['real_name' => '分类保存']);
+        //删除
+        Route::delete('security_code_record/del/:id', 'v1.user.member.SecurityCodeRecord/delete')->option(['real_name' => '删除防伪码']);
         Route::get('security_code_record/list', 'v1.user.member.SecurityCodeRecord/list')->option(['real_name' => '防伪码记录']);
         Route::get('security_code_record/set_value/:id', 'v1.user.member.SecurityCodeRecord/set_value')->option(['real_name' => '防伪码状态更新']);
         Route::post('security_code_record/save/:id', 'v1.user.member.SecurityCodeRecord/save')->option(['real_name' => '防伪码保存']);

+ 21 - 1
app/api/controller/v1/user/SecurityCodeController.php

@@ -13,7 +13,7 @@ namespace app\api\controller\v1\user;
 use app\Request;
 use app\services\user\member\SecurityCodeRecordServices;
 use app\services\user\member\SecurityCategoryServices;
-
+use crmeb\exceptions\AuthException;
 
 /**
  * 用户收藏
@@ -46,6 +46,10 @@ class SecurityCodeController
         if(!$data['wx_url']){
             return app('json')->fail(600000);
         }
+        if (mb_strlen($data['wx_url']) < 12) {
+            $data['security_code'] = $data['wx_url'];
+            $data['wx_url'] = '';
+        }
         $res = $this->services->getOneByUrl($data);
         if (!$res) {
             return app('json')->fail(600001);
@@ -74,7 +78,23 @@ class SecurityCodeController
         }
 
         $uid = (int)$request->uid();
+        if($uid<=0){
+            throw new AuthException(110002);
+        }
         $integral = $this->services->receiveSecurityCodePoint($uid, $data);
         return app('json')->success(410127, ['integral' => $integral], ['integral' => $integral]);
     }
+
+    /**
+     * 领取扫码积分
+     * @param Request $request
+     * @return mixed
+     */
+    public function     receiveSecurityCodeIndex()
+    {
+        return app('json')->success([
+            'image' => sys_config('code_image_url'),
+            'desc' => sys_config('code_rule_desc')
+        ]);
+    }
 }

+ 5 - 2
app/api/controller/v1/user/UserController.php

@@ -84,15 +84,18 @@ class UserController
      */
     public function edit(Request $request)
     {
-        list($avatar, $nickname) = $request->postMore([
+        list($avatar, $nickname,$city_id,$city_name,$store_name ) = $request->postMore([
             ['avatar', ''],
             ['nickname', ''],
+            ['city_id', ''],
+            ['city_name', ''],
+            ['store_name', '']
         ], true);
         if (!$avatar && $nickname == '') {
             return app('json')->fail(410134);
         }
         $uid = (int)$request->uid();
-        if ($this->services->eidtNickname($uid, ['avatar' => $avatar, 'nickname' => $nickname])) {
+        if ($this->services->eidtNickname($uid, ['avatar' => $avatar, 'nickname' => $nickname,'city_id' => $city_id,'city_name' => $city_name,'store_name' => $store_name ])) {
             return app('json')->success(100014);
         }
         return app('json')->fail(100015);

+ 12 - 8
app/api/route/v1.php

@@ -56,14 +56,7 @@ Route::group(function () {
     //小程序跳转url接口
     Route::get('get_scheme_url/:id', 'v1.PublicController/getSchemeUrl')->option(['real_name' => '小程序跳转url接口']);
     //远程注册用户
-    Route::get('remote_register', 'v1.LoginController/remoteRegister')->option(['real_name' => '远程注册用户']);
-
-    //查询防伪码
-    Route::get('check_security_code', 'v1.user.SecurityCodeController/checkSecurityCode')->option(['real_name' => '查询防伪码']);
-    //领取奖励
-    Route::get('receive_security_code_point', 'v1.user.SecurityCodeController/receiveSecurityCodePoint')->option(['real_name' => '领取防伪奖励']);
-
-    
+    Route::get('remote_register', 'v1.LoginController/remoteRegister')->option(['real_name' => '远程注册用户']);    
 
 })->middleware(\app\http\middleware\AllowOriginMiddleware::class)
     ->middleware(\app\api\middleware\StationOpenMiddleware::class)
@@ -502,6 +495,17 @@ Route::group(function () {
         Route::get('lang_version', 'v1.PublicController/getLangVersion')->name('getLangVersion')->option(['real_name' => '获取当前后台设置的默认语言类型']);
     })->option(['mark' => 'lang', 'mark_name' => '多语言']);
 
+    Route::group(function () {
+       
+        //查询防伪码
+        Route::get('check_security_code', 'v1.user.SecurityCodeController/checkSecurityCode')->option(['real_name' => '查询防伪码']);
+        //领取奖励
+        Route::get('receive_security_code_point', 'v1.user.SecurityCodeController/receiveSecurityCodePoint')->option(['real_name' => '领取防伪奖励']);
+        //查看防伪码页面配置
+        Route::get('receive_security_code_index', 'v1.user.SecurityCodeController/receiveSecurityCodeIndex')->option(['real_name' => '查看防伪码页面配置']);
+
+    })->option(['mark' => 'security', 'mark_name' => '防伪码']);
+
     Route::group(function () {
         /** 定时任务接口 */
         //定时任务调用接口

+ 2 - 2
app/dao/user/SecurityCodeRecordDao.php

@@ -44,7 +44,6 @@ class SecurityCodeRecordDao extends BaseDao
                 }])->when($page && $limit, function ($query) use ($page, $limit) {
                 $query->page($page, $limit);
             })->order('id desc')->select()->toArray();
-
     }
 
         /**获取会员类型api接口
@@ -52,7 +51,8 @@ class SecurityCodeRecordDao extends BaseDao
      */
     public function getOneByUrl(array $where)
     {
-        return $this->search()->where($where)->limit(1)->find();
+        // return $this->search()->where($where)->limit(1)->find();
+        return $this->search($where)->field(['*'])->limit(1)->find();
     }
 
 }

+ 4 - 1
app/dao/user/UserWechatUserDao.php

@@ -152,7 +152,10 @@ class UserWechatUserDao extends BaseDao
                 $model = $model->where($userAlias . 'pay_count', '>', $where['pay_count']);
             }
         }
-
+        //用户城市
+        if (isset($where['city_name']) && $where['city_name']) {
+            $model = $model->where($userAlias . 'city_name', 'like', "%" . trim($where['city_name']) . "%");
+        }
         //用户等级
         if (isset($where['level']) && $where['level']) {
             $model = $model->where($userAlias . 'level', $where['level']);

+ 1 - 1
app/model/user/SecurityCodeRecord.php

@@ -138,7 +138,7 @@ class SecurityCodeRecord extends BaseModel
     public function searchSecurityCodeAttr($query, $value)
     {
         if ($value) {
-            $query->whereLike('security_code', '%' . $value . '%');
+            $query->where('security_code', $value);
         }
     }
 

+ 10 - 0
app/model/user/User.php

@@ -352,6 +352,16 @@ class User extends BaseModel
         $query->where('nickname', "like", "%" . $value . "%");
     }
 
+    /**
+     * nickname搜索器
+     * @param $query
+     * @param $value
+     */
+    public function searchCityNameAttr($query, $value)
+    {
+        if ($value !== '') $query->where('city_name', "like", "%" . $value . "%");
+    }
+
     /**
      * division_type搜索器
      * @param $query

+ 38 - 1
app/services/other/export/ExportServices.php

@@ -18,6 +18,7 @@ use app\services\BaseServices;
 use app\services\order\StoreOrderServices;
 use app\services\product\product\StoreProductServices;
 use app\services\user\member\MemberCardServices;
+use app\services\user\member\SecurityCodeRecordServices;
 use app\services\user\UserServices;
 use crmeb\services\SpreadsheetExcelService;
 
@@ -33,7 +34,7 @@ class ExportServices extends BaseServices
         /** @var UserServices $userServices */
         $userServices = app()->make(UserServices::class);
         $data = $userServices->index($where)['list'];
-        $header = ['用户ID', '昵称', '真实姓名', '性别', '电话', '用户等级', '用户分组', '用户标签', '用户类型', '用户余额', '最后登录时间', '注册时间', '是否注销'];
+        $header = ['用户ID', '昵称', '真实姓名', '所属地区', '绑定门店', '性别', '电话', '用户等级', '用户分组', '用户标签', '用户类型', '用户余额','用户积分', '最后登录时间', '注册时间', '是否注销'];
         $filename = '用户列表_' . date('YmdHis', time());
         $export = $fileKey = [];
         if (!empty($data)) {
@@ -43,6 +44,8 @@ class ExportServices extends BaseServices
                     'uid' => $item['uid'],
                     'nickname' => $item['nickname'],
                     'real_name' => $item['real_name'],
+                    'city_name' => $item['city_name'],
+                    'store_name' => $item['store_name'],
                     'sex' => $item['sex'],
                     'phone' => $item['phone'],
                     'level' => $item['level'],
@@ -50,6 +53,7 @@ class ExportServices extends BaseServices
                     'labels' => $item['labels'],
                     'user_type' => $item['user_type'],
                     'now_money' => $item['now_money'],
+                    'integral' => $item['integral'],
                     'last_time' => date('Y-m-d H:i:s', $item['last_time']),
                     'add_time' => date('Y-m-d H:i:s', $item['add_time']),
                     'is_del' => $item['is_del'] ? '已注销' : '正常'
@@ -948,4 +952,37 @@ class ExportServices extends BaseServices
         $is_save = true;
         return $this->export($header, $title, $export, $filename, $suffix, $is_save);
     }
+
+    public function exportCodeList(array $where)
+    {
+        $header = ['ID', '防伪码编号', '产品名称', '价格', '赠送积分', '导入时间', '状态','扫码用户','所属地区','绑定门店','扫码时间'];
+        $filename = '防伪码列表_' . date('YmdHis', time());
+        $export = $fileKey = [];
+        $securityCodeRecordServices = app()->make(SecurityCodeRecordServices::class);
+        $data = $securityCodeRecordServices->getSearchAllList($where)['list'];
+        if (!empty($data)) {
+            $i = 0;
+            foreach ($data as $item) {
+                $one_data = [
+                    'id' => $item['id'],
+                    'security_code' => $item['security_code'],
+                    'category_name' => $item['category_name'],
+                    'price' => $item['price'],
+                    'point' => $item['point'],
+                    'add_time' => $item['add_time'] ? $item['add_time'] : '-',
+                    'status' => $item['status'] == 2 ? '已使用' : '未使用',
+                    'scan_name' => $item['scan_name'],
+                    'city_name' => $item['city_name'],
+                    'store_name' => $item['store_name'],
+                    'scan_time' => $item['scan_time'] ? $item['scan_time'] : '-'
+                ];
+                $export[] = $one_data;
+                if ($i == 0) {
+                    $fileKey = array_keys($one_data);
+                }
+                $i++;
+            }
+        }
+        return compact('header', 'fileKey', 'export', 'filename');
+    }
 }

+ 1 - 0
app/services/product/product/StoreProductServices.php

@@ -2070,4 +2070,5 @@ class StoreProductServices extends BaseServices
         }
         return true;
     }
+
 }

+ 5 - 5
app/services/user/UserWechatuserServices.php

@@ -51,11 +51,11 @@ class UserWechatuserServices extends BaseServices
     public function getWhereUserList(array $where, string $field): array
     {
         [$page, $limit] = $this->getPageValue();
-        $order_string = '';
-        $order_arr = ['ascending', 'descending'];
-        if (isset($where['now_money']) && in_array($where['now_money'], $order_arr)) {
-            $order_string = $where['now_money'] == 'ascending' ? 'now_money asc' : 'now_money desc';
-        }
+        $order_string = 'integral desc';
+//        $order_arr = ['ascending', 'descending'];
+//        if (isset($where['now_money']) && in_array($where['now_money'], $order_arr)) {
+//            $order_string = $where['now_money'] == 'ascending' ? 'now_money asc' : 'now_money desc';
+//        }
         $list = $this->dao->getListByModel($where, $field, $order_string, $page, $limit);
         $count = $this->dao->getCountByWhere($where);
         return [$list, $count];

+ 72 - 14
app/services/user/member/SecurityCodeRecordServices.php

@@ -51,9 +51,15 @@ class SecurityCodeRecordServices extends BaseServices
             $item['point'] = $item['category']['point'] ?? '';
             $item['category_name'] = $item['category']['name'] ?? '';
             $item['category_status'] = $item['category']['status'] ?? '';
+            $item['scan_name'] = '-';
+            $item['city_name'] = '-';
+            $item['store_name'] = '-';
+            $item['scan_phone'] = '-';
 			if($item['scan_uid']){
 				$userInfo = $userServices->getUserInfo((int)$item['scan_uid']);
-                $item['scan_name'] = $userInfo['nickname'] ?? '';
+                $item['scan_name'] = $userInfo['nickname']."-".$userInfo['phone'];
+                $item['city_name'] = $userInfo['city_name'] ?? '';
+                $item['store_name'] = $userInfo['store_name'] ?? '';
 				$item['scan_phone'] = $userInfo['phone'] ?? '';
 			}
 			unset($item['category']);
@@ -62,6 +68,40 @@ class SecurityCodeRecordServices extends BaseServices
         return compact('list', 'count');
     }
 
+    /**
+     * @param array $where
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function getSearchAllList(array $where = [])
+    {
+        [$page, $limit] = $this->getPageValue();
+        $list = $this->dao->getSearchList($where);
+        $userServices = app()->make(UserServices::class);
+        foreach ($list as &$item) {
+            $item['price'] = $item['category']['price'] ?? '';
+            $item['point'] = $item['category']['point'] ?? '';
+            $item['category_name'] = $item['category']['name'] ?? '';
+            $item['category_status'] = $item['category']['status'] ?? '';
+            $item['scan_name'] = '-';
+            $item['city_name'] = '-';
+            $item['store_name'] = '-';
+            $item['scan_phone'] = '-';
+            if($item['scan_uid']){
+                $userInfo = $userServices->getUserInfo((int)$item['scan_uid']);
+                $item['scan_name'] = $userInfo['nickname']."-".$userInfo['phone'];
+                $item['city_name'] = $userInfo['city_name'] ?? '';
+                $item['store_name'] = $userInfo['store_name'] ?? '';
+                $item['scan_phone'] = $userInfo['phone'] ?? '';
+            }
+            unset($item['category']);
+        }
+        $count = $this->dao->count($where);
+        return compact('list', 'count');
+    }
+
         /**获取会员卡api接口
      * @return mixed
      */
@@ -76,6 +116,15 @@ class SecurityCodeRecordServices extends BaseServices
      */
     public function receiveSecurityCodePoint(int $uid, array $data)
     {
+        /** @var UserServices $userServices */
+        $userServices = app()->make(UserServices::class);
+
+        //检测用户是否存在
+        $user = $userServices->getUserInfo($uid);
+        if (!$user) {
+            throw new ApiException(100026);
+        }
+
         $codeRecord = $this->dao->getOne($data);
         if(!$codeRecord){
             throw new ApiException(600001);
@@ -83,41 +132,35 @@ class SecurityCodeRecordServices extends BaseServices
         if($codeRecord['status']==2){
             throw new ApiException(600003);
         }
-        /** @var UserServices $userServices */
-        $userServices = app()->make(UserServices::class);
 
-        //检测用户是否存在
-        $user = $userServices->getUserInfo($uid);
-        if (!$user) {
-            throw new ApiException(410032);
-        }
         $categoryServices = app()->make(SecurityCategoryServices::class);
         $cateInfo = $categoryServices->getOne(['id' => $codeRecord['category_id']]);
         
         $codeRecord['status'] = 2;
         $codeRecord['scan_uid'] = $uid;
         $codeRecord['scan_time'] = time();
-        $point = $codeRecord['id'];
+        $point = $cateInfo['point'];
         
         $data = [];
         $data['uid'] = $uid;
-        $data['link_id'] = $point;
-        $data['title'] = "扫码领积分";
+        $data['link_id'] = $codeRecord['id'];
+        $data['title'] = "扫防伪码领积分";
         $data['number'] = $cateInfo['point'];
         $data['add_time'] = time();
         /** @var UserBillServices $userBill */
         $userBill = app()->make(UserBillServices::class);
-        $data['mark'] = "扫码领取了".$point."积分";
+        $data['mark'] = "扫防伪码领取了".$point."积分";
 
         //增加数据
         $this->transaction(function () use ($uid, $userBill, $codeRecord, $data, $user, $point) {
             //保存记录
             $this->dao->update($codeRecord['id'], ['status' => 2, 'scan_uid' => $uid, 'scan_time' => time()]);
-            $userBill->incomeIntegral($uid, 'security', $data);
+            $data['balance'] = (int)$user['integral'] + (int)$point;
+            $userBill->incomeIntegral($user['uid'], 'system_add', $data);
             //保存积分
             $user->integral = (int)$user->integral + (int)$point;
             if (!$user->save()) {
-                throw new ApiException(410287);
+                throw new ApiException(400692);
             }
         });
         //检测会员等级
@@ -178,4 +221,19 @@ class SecurityCodeRecordServices extends BaseServices
         return false;
     }
 
+    public function delCode(int $id)
+    {
+        if ($this->getById($id)) {
+            if (!$this->dao->delete($id)) {
+                throw new AdminException(100008);
+            }
+        }
+        return true;
+    }
+
+    public function getById($id)
+    {
+        return $this->dao->get($id);
+    }
+
 }

+ 38 - 0
doc/union.sql

@@ -0,0 +1,38 @@
+CREATE TABLE `eb_security_category` (
+                                        `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增ID',
+                                        `name` varchar(50) CHARACTER SET utf8mb4 NOT NULL DEFAULT '' COMMENT '类别名称',
+                                        `price` decimal(12,2) NOT NULL DEFAULT '0.00' COMMENT '分类商品价格',
+                                        `point` int(6) NOT NULL DEFAULT '0' COMMENT '赠送积分',
+                                        `status` tinyint(1) NOT NULL DEFAULT '0' COMMENT '卡状态:0:冻结;1:激活',
+                                        `remark` varchar(100) DEFAULT NULL COMMENT '备注',
+                                        `add_time` int(10) NOT NULL DEFAULT '0' COMMENT '添加时间',
+                                        `update_time` int(10) NOT NULL DEFAULT '0' COMMENT '更新时间',
+                                        PRIMARY KEY (`id`) USING BTREE
+) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='防伪码类别';
+
+
+CREATE TABLE `eb_security_code_record` (
+                                           `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '自增ID',
+                                           `category_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '类别id',
+                                           `security_code` varchar(30) CHARACTER SET utf8mb4 NOT NULL DEFAULT '' COMMENT '防伪码编码',
+                                           `wx_url` varchar(100) CHARACTER SET utf8mb4 NOT NULL DEFAULT '' COMMENT '微信扫码链接地址',
+                                           `scan_uid` int(11) DEFAULT NULL COMMENT '扫码使用用户',
+                                           `scan_time` int(10) DEFAULT NULL COMMENT '首次扫码时间',
+                                           `status` tinyint(1) DEFAULT NULL COMMENT '防伪码状态:0:冻结;1:激活 2:已使用',
+                                           `add_time` int(10) NOT NULL DEFAULT '0' COMMENT '添加时间',
+                                           `update_time` int(10) NOT NULL DEFAULT '0' COMMENT '更新时间',
+                                           PRIMARY KEY (`id`) USING BTREE,
+                                           UNIQUE KEY `udx_code` (`security_code`) USING HASH
+) ENGINE=InnoDB AUTO_INCREMENT=22009 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='防伪码记录';
+
+alter table eb_user add column
+
+    `city_id` int(11) NOT NULL DEFAULT '0' COMMENT '城市id';
+
+alter table eb_user add column
+
+    `city_name` varchar(100) NOT NULL DEFAULT '' COMMENT '所在市';
+
+alter table eb_user add column
+
+    `store_name` varchar(100) NOT NULL DEFAULT '' COMMENT '门店名称';