Ver Fonte

Merge branch 'dev_wf' of wufeng/fuse into version1.5

wufeng há 2 anos atrás
pai
commit
6cde356c03

+ 36 - 11
app/admin/config/validate_rules.php

@@ -135,24 +135,49 @@ return [
 
     //【视频分组】
     //添加
-    'VideoGroupAdd'=>[
-        'company_id|企业id'=>'require|number|gt:0',
-        'card_id|卡类型id'=>'require|number|gt:0',
-        'video_list|视频集合'=>'require|array|min:1|max:100',
+    'VideoGroupAdd' => [
+        'company_id|企业id' => 'require|number|gt:0',
+        'card_id|卡类型id' => 'require|number|gt:0',
+        'video_list|视频集合' => 'require|array|min:1|max:100',
     ],
     //【商品分组】
     //添加
-    'GoodGroupAdd'=>[
-        'company_id|企业id'=>'require|number|gt:0',
-        'card_id|卡类型id'=>'require|number|gt:0',
-        'good_list|商品集合'=>'require|array|min:1|max:100',
+    'GoodGroupAdd' => [
+        'company_id|企业id' => 'require|number|gt:0',
+        'card_id|卡类型id' => 'require|number|gt:0',
+        'good_list|商品集合' => 'require|array|min:1|max:100',
     ],
 
     //【商城商品库存】
     //添加
-    'InventoryShoppingAdd'=>[
-        'good_id|商品id'=>'require|number|gt:0',
-        'inventory|库存数'=>'require|number|gt:0|lt:999999999',
+    'InventoryShoppingAdd' => [
+        'good_id|商品id' => 'require|number|gt:0',
+        'inventory|库存数' => 'require|number|gt:0|lt:999999999',
+    ],
+
+    //【账户】
+    //添加
+    'AccountAdd' => [
+        'company_id|企业' => 'require|number|gt:0',
+        'card_id|卡类型' => 'require|number|gt:0',
+        'username|账户' => 'require|max:255',
+        'starttime|开始日期' => 'require|date|lt:expiretime',
+        'expiretime|结束日期' => 'require|date|gt:starttime',
+        'video_ids|视频id集合' => 'require|array|max:100',
+        'mobile|手机号' => 'mobile',
+        'name|姓名' => 'max:255',
+        'remark|备注' => 'max:255',
+    ],
+    //批量添加账户
+    'AccountBatchAdd' => [
+        'company_id|企业' => 'require|number|gt:0',
+        'card_id|卡类型' => 'require|number|gt:0',
+        'username_prefix|账户前缀' => 'require|max:255',
+        'suffix_start|账户后缀起始值' => 'require|number|max:9999|lt:suffix_end',
+        'suffix_end|账户后缀结束值' => 'require|number|max:9999|gt:suffix_start',
+        'starttime|开始日期' => 'require|date|lt:expiretime',
+        'expiretime|结束日期' => 'require|date|gt:starttime',
+        'video_ids|视频id集合' => 'require|array|max:100',
     ],
 
 ];

+ 76 - 0
app/admin/controller/Account.php

@@ -0,0 +1,76 @@
+<?php
+
+
+namespace app\admin\controller;
+
+
+use app\admin\logic\AccountLogic;
+use app\BaseController;
+use think\exception\ValidateException;
+use think\facade\Config;
+use think\facade\Validate;
+
+class Account extends BaseController
+{
+    //账户列表
+    public function list()
+    {
+
+        $param = $this->request->only(['page' => 1, 'size' => 10, 'username' => '', 'name' => '', 'mobile' => ''], 'post');
+
+        return AccountLogic::list($param);
+
+    }
+
+    //添加账户
+    public function add()
+    {
+        $param = $this->request->only(['company_id', 'card_id', 'username', 'starttime', 'expiretime', 'video_ids', 'mobile' => '', 'name' => '', 'remark' => ''], 'post');
+
+        $val = Validate::rule(Config::get('validate_rules.AccountAdd'));
+
+        if (!$val->check($param)) throw new ValidateException($val->getError());
+
+        return AccountLogic::add($param);
+    }
+
+    //账户详情
+    public function read()
+    {
+        $id = $this->request->post('id/d', 0);
+        return AccountLogic::read($id);
+    }
+
+    //编辑账户
+    public function edit()
+    {
+        $param = $this->request->only(['id', 'company_id', 'card_id', 'username', 'starttime', 'expiretime', 'video_ids', 'mobile' => '', 'name' => '', 'remark' => ''], 'post');
+
+        $val = Validate::rule(array_merge(Config::get('validate_rules.AccountAdd'), ['id' => ['require|number|gt:0']]));
+
+        if (!$val->check($param)) throw new ValidateException($val->getError());
+
+        return AccountLogic::edit($param);
+    }
+
+    //批量添加账户
+    public function batchAdd()
+    {
+
+        $param = $this->request->only(['company_id', 'card_id', 'username_prefix', 'suffix_start', 'suffix_end', 'starttime', 'expiretime', 'video_ids'], 'post');
+
+        $val = Validate::rule(Config::get('validate_rules.AccountBatchAdd'));
+
+        if (!$val->check($param)) throw new ValidateException($val->getError());
+
+        return AccountLogic::batchAdd($param);
+    }
+
+    //删除
+    public function delete()
+    {
+        $id = $this->request->post('id/d', 0);
+        return AccountLogic::delete($id);
+    }
+
+}

+ 165 - 0
app/admin/logic/AccountLogic.php

@@ -0,0 +1,165 @@
+<?php
+
+namespace app\admin\logic;
+
+use app\model\AccountModel;
+use app\model\CommonModel;
+use think\facade\Db;
+use think\response\Json;
+
+class AccountLogic extends BaseLogic
+{
+
+    //列表
+    public static function list(array $data = []): Json
+    {
+        $db = AccountModel::alias('a')
+            ->leftJoin('company b', 'b.id=a.company_id AND b.is_del=' . CommonModel::$del_normal)
+            ->leftJoin('card c', 'c.id=a.card_id AND c.is_del=' . CommonModel::$del_normal)
+            ->where('a.is_del', CommonModel::$del_normal);
+
+        if ($data['username'] != '') $db->whereLike('a.username', '%' . $data['username'] . '%');
+        if ($data['name'] != '') $db->whereLike('a.name', '%' . $data['name'] . '%');
+        if ($data['mobile'] != '') $db->whereLike('a.mobile', '%' . $data['mobile'] . '%');
+
+        $count = $db->count('a.id');
+
+        $list = $db
+            ->field('a.id,a.username,a.status,a.name,b.title company_title,c.title card_title,a.mobile,a.remark,a.activetime,a.expiretime')
+            ->order('a.id', 'desc')
+            ->page($data['page'], $data['size'])
+            ->select()
+            ->toArray();
+        return json_show(CommonModel::$success, '获取账户列表成功', ['count' => $count, 'list' => $list]);
+    }
+
+    //添加
+    public static function add(array $data = []): Json
+    {
+        $rs = AccountModel::field('id,username')
+            ->where('is_del', CommonModel::$del_normal)
+            ->where('username', $data['username'])
+            ->findOrEmpty()
+            ->isEmpty();
+        if (!$rs) return json_show(CommonModel::$error_param, '该账号已存在');
+
+        $pwd = randomkeys(6);
+        $salt = randomkeys(4);
+        $date = date('Y-m-d H:i:s');
+
+        $res = AccountModel::create([
+            'username' => $data['username'],
+            'pwd' => $pwd,
+            'salt' => $salt,
+            'password' => getPassword($pwd, $salt),
+            'company_id' => $data['company_id'],
+            'card_id' => $data['card_id'],
+            'video_ids' => implode(',', $data['video_ids']),
+            'status' => AccountModel::$status_not_active,
+            'is_del' => CommonModel::$del_normal,
+            'starttime' => $data['starttime'],
+            'expiretime' => $data['expiretime'],
+            'createrid' => self::$uid,
+            'creater' => self::$uname,
+            'addtime' => $date,
+            'updaterid' => self::$uid,
+            'updater' => self::$uname,
+            'updatetime' => $date,
+        ])->save();
+
+        return $res ? json_show(CommonModel::$success, '账户添加成功') : json_show(CommonModel::$error_param, '账户添加失败');
+
+    }
+
+    //读取
+    public static function read(int $id = 0): Json
+    {
+        $res = AccountModel::field(true)
+            ->where(['id' => $id, 'is_del' => CommonModel::$del_normal])
+            ->withAttr('video_ids', function ($val) {
+                return explode(',', $val);
+            })
+            ->findOrEmpty()
+            ->toArray();
+
+        return $res ? json_show(CommonModel::$success, '获取账户详情成功', $res) : json_show(CommonModel::$error_param, '获取账户详情失败');
+    }
+
+    //修改
+    public static function edit(array $data = []): Json
+    {
+
+        $date = date('Y-m-d H:i:s');
+
+        $res = AccountModel::where(['id' => $data['id'], 'is_del' => CommonModel::$del_normal])
+            ->save([
+                'username' => $data['username'],
+                'company_id' => $data['company_id'],
+                'card_id' => $data['card_id'],
+                'video_ids' => implode(',', $data['video_ids']),
+                'starttime' => $data['starttime'],
+                'expiretime' => $data['expiretime'],
+                'updaterid' => self::$uid,
+                'updater' => self::$uname,
+                'updatetime' => $date,
+            ]);
+
+        return $res ? json_show(CommonModel::$success, '账户修改成功') : json_show(CommonModel::$error_param, '账户修改失败');
+
+    }
+
+    //批量添加账户
+    public static function batchAdd(array $data = []): Json
+    {
+        $usernames = [];
+
+        $date = date('Y-m-d H:i:s');
+
+        for ($i = $data['suffix_start']; $i <= $data['suffix_end']; $i++) {
+            $pwd = randomkeys(6);
+            $salt = randomkeys(4);
+            $usernames[] = [
+                'username' => $data['username_prefix'] . str_pad($i, 4, '0', STR_PAD_LEFT),
+                'pwd' => $pwd,
+                'salt' => $salt,
+                'password' => getPassword($pwd, $salt),
+                'company_id' => $data['company_id'],
+                'card_id' => $data['card_id'],
+                'video_ids' => implode(',', $data['video_ids']),
+                'status' => AccountModel::$status_not_active,
+                'is_del' => CommonModel::$del_normal,
+                'starttime' => $data['starttime'],
+                'expiretime' => $data['expiretime'],
+                'createrid' => self::$uid,
+                'creater' => self::$uname,
+                'addtime' => $date,
+                'updaterid' => self::$uid,
+                'updater' => self::$uname,
+                'updatetime' => $date,
+            ];
+        }
+
+        $rs = AccountModel::field('id,username')
+            ->where('is_del', CommonModel::$del_normal)
+            ->whereIn('username', array_column($usernames, 'username'))
+            ->findOrEmpty();
+        if (!$rs->isEmpty()) return json_show(CommonModel::$error_param, $rs->username . '账号已存在');
+
+        $res = Db::name('account')->insertAll($usernames);
+
+        return $res ? json_show(CommonModel::$success, $res . '个账户批量添加成功') : json_show(CommonModel::$error_param, '批量添加账户失败');
+
+    }
+
+    //删除
+    public static function delete(int $id = 0): Json
+    {
+        $rs = AccountModel::where(['id' => $id, 'is_del' => CommonModel::$del_normal])
+            ->where('status', '<>', AccountModel::$status_activated)
+            ->save(['is_del' => CommonModel::$del_deleted, 'updatetime' => date('Y-m-d H:i:s')]);
+
+        return $rs ? json_show(CommonModel::$success, '删除成功') : json_show(CommonModel::$error_param, '删除失败,该账户不存在或不允许删除');
+    }
+
+
+}

+ 10 - 0
app/admin/route/app.php

@@ -105,3 +105,13 @@ Route::rule('InventoryShoppingEdit', 'admin/InventoryShopping/edit');//编辑商
 Route::rule('InventoryShoppingLog', 'admin/InventoryShopping/log');//商城商品库存变动记录
 
 
+//【账户】
+Route::rule('AccoountBatchAdd', 'admin/Account/batchAdd');//批量添加账户
+Route::rule('AccoountAdd', 'admin/Account/add');//添加
+Route::rule('AccoountList', 'admin/Account/list');//列表
+Route::rule('AccoountRead', 'admin/Account/read');//读取
+Route::rule('AccoountEdit', 'admin/Account/edit');//修改
+Route::rule('AccoountDelete', 'admin/Account/delete');//删除
+
+
+

+ 1 - 1
app/admin/validate/GoodValidate.php

@@ -12,7 +12,7 @@ class GoodValidate extends Validate
 
     //验证规则
     protected $rule = [
-        'good_cover_img|商品封面图' => 'require|max:255|url',
+        'good_cover_img|商品封面图' => 'require|max:255',
         'good_name|商品名称' => 'require|max:255',
         'moq|销售起订量' => 'require|number|min:1|max:999999999',
         'step|销售步长' => 'require|number|min:1|max:999999999',

+ 1 - 33
app/common.php

@@ -14,7 +14,7 @@ if (!function_exists('json_show')) {
     }
 }
 
-//获取密码
+//获取加密后的密码
 //@param $password string 密码
 //@param $salt string 盐值
 if (!function_exists('getPassword')) {
@@ -104,38 +104,6 @@ if (!function_exists('curl_request')) {
     }
 }
 
-//上传图片
-if (!function_exists('upload_img')) {
-    function upload_img($files)
-    {
-        $savename = [];
-        $files = !is_array($files) ? [$files] : $files;
-        //验证
-        validate([
-            'imgFile' => [
-                'fileSize' => 10240000,
-                'fileExt' => 'jpg,jpeg,png,bmp,gif',
-                'fileMime' => 'image/jpeg,image/png,image/gif'
-            ]
-        ])->check(['imgFile' => $files]);
-
-        $domain = request()->domain() . Config::get('filesystem.disks.public.url') . DIRECTORY_SEPARATOR;
-
-
-        foreach ($files as $file) {
-            $url = Filesystem::disk('public')->putFile('topic/' . date('Ymd'), $file, function () use ($file) {
-                return str_replace('.' . $file->getOriginalExtension(), '', $file->getOriginalName() . '_' . date('YmdHis'));
-            });
-            $name = str_replace('.' . $file->getOriginalExtension(), '', $file->getOriginalName());
-            $temp = ['url' => $domain . $url, 'name' => $name];
-            $savename[] = $temp;
-        }
-
-        return $savename;
-
-    }
-}
-
 //生成编码
 //@param $str string 前缀
 if (!function_exists('makeNo')) {

+ 6 - 0
app/model/AccountModel.php

@@ -8,5 +8,11 @@ class AccountModel extends Model
 {
     protected $table = 'fc_account';
     protected $pk = 'id';
+    protected $hidden = ['password', 'salt', 'pwd'];
+
+    //状态
+    public static $status_not_active = 0;//未激活
+    public static $status_activated = 1;//已激活
+    public static $status_invalid = 2;//已失效
 
 }