moonsflyer пре 6 месеци
родитељ
комит
5f437a3efc

+ 109 - 0
app/adminapi/controller/gift_card/GiftCardController.php

@@ -0,0 +1,109 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeshop开源商城系统
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | gitee下载:https://gitee.com/likeshop_gitee
+// | github下载:https://github.com/likeshop-github
+// | 访问官网:https://www.likeshop.cn
+// | 访问社区:https://home.likeshop.cn
+// | 访问手册:http://doc.likeshop.cn
+// | 微信公众号:likeshop技术社区
+// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
+// |  likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
+// | 禁止对系统程序代码以任何目的,任何形式的再发布
+// | likeshop团队版权所有并拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeshop.cn.team
+// +----------------------------------------------------------------------
+
+namespace app\adminapi\controller\gift_card;
+
+
+use app\adminapi\controller\BaseAdminController;
+use app\adminapi\lists\gift_card\GiftCardLists;
+use app\adminapi\lists\gift_card\GiftCardInfoLists;
+use app\adminapi\validate\gift_card\GiftCardValidate;
+use app\adminapi\logic\gift_card\GiftCardLogic;
+
+class GiftCardController extends BaseAdminController
+{
+    /**
+     * @notes 礼品卡批次列表
+     * @return \think\response\Json
+     * @author ljj
+     * @date 2022/3/30 5:40 下午
+     */
+    public function lists()
+    {
+        return $this->dataLists(new GiftCardLists());
+    }
+
+    /**
+     * @notes 新增礼品卡
+     * @return \think\response\Json
+     * @author ljj
+     * @date 2022/3/31 11:23 上午
+     */
+    public function add()
+    {
+        if($this->request->isPost()) {
+
+        $params = (new GiftCardValidate())->post()->goCheck('add');
+        $result = (new GiftCardLogic())->add($params);
+
+        if($result == 'true'){
+            return $this->success('新增礼品卡成功');
+        }else{
+            return $this->fail(GiftCardLogic::getError());
+        }
+
+        }else{
+            return $this->fail('请求方式错误');
+        }
+    }
+
+    /**
+     * @notes 礼品卡批次卡号详情
+     * @return \think\response\Json
+     * @author ljj
+     * @date 2022/3/31 11:23 上午
+     */
+    public function cardDetail()
+    {
+        $params = (new GiftCardValidate())->goCheck('detail');
+        return $this->dataLists(new GiftCardInfoLists());
+    }
+
+    /**
+     * @notes 删除批次
+     * @return \think\response\Json
+     * @author ljj
+     * @date 2022/3/31 2:29 下午
+     */
+    public function delGiftCard()
+    {
+        $params = (new GiftCardValidate())->post()->goCheck('delGiftCard');
+        $result = (new GiftCardLogic())->deleteGiftCard($params);
+        if (true !== $result) {
+            return $this->fail(GiftCardLogic::getError());
+        }
+        return $this->success('删除成功',[],1,1);
+    }
+
+    /**
+     * @notes 删除礼品卡
+     * @return \think\response\Json
+     * @author ljj
+     * @date 2022/3/31 2:29 下午
+     */
+    public function delGiftCardInfo()
+    {
+        $params = (new GiftCardValidate())->post()->goCheck('delGiftCardInfo');
+        $result = (new GiftCardLogic())->deleteGiftCardInfo($params);
+        if (true !== $result) {
+            return $this->fail(GiftCardLogic::getError());
+        }
+        return $this->success('删除成功',[],1,1);
+    }
+}

+ 91 - 0
app/adminapi/lists/gift_card/GiftCardInfoLists.php

@@ -0,0 +1,91 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeshop开源商城系统
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | gitee下载:https://gitee.com/likeshop_gitee
+// | github下载:https://github.com/likeshop-github
+// | 访问官网:https://www.likeshop.cn
+// | 访问社区:https://home.likeshop.cn
+// | 访问手册:http://doc.likeshop.cn
+// | 微信公众号:likeshop技术社区
+// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
+// |  likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
+// | 禁止对系统程序代码以任何目的,任何形式的再发布
+// | likeshop团队版权所有并拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeshop.cn.team
+// +----------------------------------------------------------------------
+
+namespace app\adminapi\lists\gift_card;
+
+
+use app\adminapi\lists\BaseAdminDataLists;
+use app\common\model\GiftCardInfo;
+
+class GiftCardInfoLists extends BaseAdminDataLists
+{
+    /**
+     * @notes 搜索条件
+     * @return array
+     * @author ljj
+     * @date 2022/3/30 5:12 下午
+     */
+    public function setSearch(): array
+    {
+        $where = [];
+        $params = $this->params;
+
+        //下单时间
+        if (isset($params['start_time']) && $params['start_time'] != '') {
+            $where[] = ['create_time', '>=', strtotime($params['start_time'])];
+        }
+        if (isset($params['end_time']) && $params['end_time'] != '') {
+            $where[] = ['create_time', '<=', strtotime($params['end_time'])];
+        }
+        $where[]=['gc_id','=',$params['id']];
+
+        if(isset($params['card_no'])){
+            $where[] = ['card_no', 'like', '%' . $params['card_no'] . '%'];
+        }
+
+        return $where;
+    }
+
+    /**
+     * @notes 礼品卡列表
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @author ljj
+     * @date 2022/3/30 5:40 下午
+     */
+    public function lists(): array
+    {
+        $lists = GiftCardInfo::where($this->setSearch())
+            ->with(['user'])
+            ->append(['is_used_desc'])
+            ->limit($this->limitOffset, $this->limitLength)
+            ->order('id', 'desc')
+            ->select()
+            ->toArray();
+
+        foreach ($lists as &$list) {
+//            $list['goods_snap']['image'] = FileService::getFileUrl($list['goods_snap']['image']);
+        }
+
+        return $lists;
+    }
+
+    /**
+     * @notes 兑换订单数量
+     * @return int
+     * @author ljj
+     * @date 2022/3/30 5:40 下午
+     */
+    public function count(): int
+    {
+        return GiftCardInfo::where($this->setSearch())->count();
+    }
+}

+ 86 - 0
app/adminapi/lists/gift_card/GiftCardLists.php

@@ -0,0 +1,86 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeshop开源商城系统
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | gitee下载:https://gitee.com/likeshop_gitee
+// | github下载:https://github.com/likeshop-github
+// | 访问官网:https://www.likeshop.cn
+// | 访问社区:https://home.likeshop.cn
+// | 访问手册:http://doc.likeshop.cn
+// | 微信公众号:likeshop技术社区
+// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
+// |  likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
+// | 禁止对系统程序代码以任何目的,任何形式的再发布
+// | likeshop团队版权所有并拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeshop.cn.team
+// +----------------------------------------------------------------------
+
+namespace app\adminapi\lists\gift_card;
+
+
+use app\adminapi\lists\BaseAdminDataLists;
+use app\common\model\IntegralOrder;
+use app\common\model\GiftCard;
+use app\common\service\FileService;
+
+class GiftCardLists extends BaseAdminDataLists
+{
+    /**
+     * @notes 搜索条件
+     * @return array
+     * @author ljj
+     * @date 2022/3/30 5:12 下午
+     */
+    public function setSearch(): array
+    {
+        $where = [];
+        $params = $this->params;
+
+        //下单时间
+        if (isset($params['start_time']) && $params['start_time'] != '') {
+            $where[] = ['create_time', '>=', strtotime($params['start_time'])];
+        }
+        if (isset($params['end_time']) && $params['end_time'] != '') {
+            $where[] = ['create_time', '<=', strtotime($params['end_time'])];
+        }
+
+        return $where;
+    }
+
+    /**
+     * @notes 礼品卡批次列表
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @author ljj
+     * @date 2022/3/30 5:40 下午
+     */
+    public function lists(): array
+    {
+        $lists = GiftCard::where($this->setSearch())
+            ->limit($this->limitOffset, $this->limitLength)
+            ->order('id', 'desc')
+            ->select()
+            ->toArray();
+
+//        foreach ($lists as &$list) {
+////            $list['goods_snap']['image'] = FileService::getFileUrl($list['goods_snap']['image']);
+//        }
+
+        return $lists;
+    }
+
+    /**
+     * @notes 兑换订单数量
+     * @return int
+     * @author ljj
+     * @date 2022/3/30 5:40 下午
+     */
+    public function count(): int
+    {
+        return GiftCard::where($this->setSearch())->count();
+    }
+}

+ 203 - 0
app/adminapi/logic/gift_card/GiftCardLogic.php

@@ -0,0 +1,203 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeshop开源商城系统
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | gitee下载:https://gitee.com/likeshop_gitee
+// | github下载:https://github.com/likeshop-github
+// | 访问官网:https://www.likeshop.cn
+// | 访问社区:https://home.likeshop.cn
+// | 访问手册:http://doc.likeshop.cn
+// | 微信公众号:likeshop技术社区
+// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
+// |  likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
+// | 禁止对系统程序代码以任何目的,任何形式的再发布
+// | likeshop团队版权所有并拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeshop.cn.team
+// +----------------------------------------------------------------------
+
+namespace app\adminapi\logic\gift_card;
+
+
+use app\common\enum\IntegralDeliveryEnum;
+use app\common\enum\IntegralGoodsEnum;
+use app\common\enum\IntegralOrderEnum;
+use app\common\enum\IntegralOrderRefundEnum;
+use app\common\enum\NoticeEnum;
+use app\common\enum\PayEnum;
+use app\common\logic\BaseLogic;
+use app\common\logic\IntegralOrderRefundLogic;
+use app\common\model\Cart;
+use app\common\model\Express;
+use app\common\model\IntegralDelivery;
+use app\common\model\IntegralOrder;
+use app\common\model\GiftCardInfo;
+use app\common\model\GiftCard;
+use app\common\service\ConfigService;
+use app\common\service\FileService;
+use expressage\Kd100;
+use expressage\Kdniao;
+use think\facade\Db;
+
+class GiftCardLogic extends BaseLogic
+{
+    /**
+     * @notes 新增礼品卡
+     * @param $params
+     * @return bool|string
+     * @author ljj
+     * @date 2022/3/31 2:29 下午
+     */
+    public function add($params)
+    {
+        Db::startTrans();
+        try {
+            $num = $params['num'];
+            $money = $params['money'];
+
+            $gift_card_max_no = GiftCardInfo::where(['type'=>1])->max('card_no');
+
+            if(empty($gift_card_max_no)) {
+                $start_no = 100000001;
+            }else{
+                $start_no = $gift_card_max_no+1;
+            }
+            $end_no = $start_no + $num -1;
+            $nowtime = time();
+            $todaytime = date('Y-m-d',$nowtime);
+            $where = [];
+            $where[]=['create_time','>',strtotime($todaytime)];
+            $card_info = GiftCard::where($where)->order('create_time desc')->find();
+            if($card_info){
+                $date = $card_info['date'] +1;
+            }else{
+                $date =date('Ymd',$nowtime).'00001';
+            }
+
+
+            //添加批次信息
+            $card_data = [
+                'date' =>$date,
+                'type' =>1,
+                'card_remark' => $start_no.'~'.$end_no,
+                'card_money' => $money,
+                'total_num' => $num,
+                'create_time' => time(),
+            ];
+
+            $gift_card = GiftCard::create($card_data);
+
+            if(!$gift_card){
+                Db::rollback();
+                self::setError('插入批次信息错误!');
+            }
+
+            $gc_id = $gift_card['id'];
+
+            $gcidata = [];
+            $saveData = [];
+            $saveData['gc_id'] = $gc_id;
+            $saveData['type'] = 1;
+            $saveData['card_money'] = $money;
+            $saveData['is_used'] = 0;
+            $saveData['create_time'] = time();
+            for($i = 1;$i<=$num;$i++){
+                $saveData['card_no'] = $start_no;
+                $pass = gift_card_pass();
+                $saveData['card_pass'] = $pass;
+                $start_no ++;
+                $gcidata[]=$saveData;
+            }
+            if(!empty($gcidata)){
+                $gCobj = new GiftCardInfo();
+
+                $card_add_info = $gCobj->saveAll($gcidata);
+                if(!$card_add_info){
+                    Db::rollback();
+                    self::setError('插入礼品卡信息错误,请重试!');
+                }
+            }
+
+            // 提交事务
+            Db::commit();
+            return true;
+        } catch (\Exception $e) {
+            // 回滚事务
+            Db::rollback();
+            return $e->getMessage();
+        }
+    }
+
+    /**
+     * @notes 删除批次信息
+     * @param $params
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @author ljj
+     * @date 2022/3/31 2:37 下午
+     */
+    public function deleteGiftCard($params)
+    {
+        Db::startTrans();
+        try {
+
+
+            $res = GiftCard::destroy($params['id']);
+            // 提交事务
+
+            if(!$res){
+                Db::rollback();
+                self::setError('删除批次信息错误!');
+            }
+
+            $res2 = GiftCardInfo::where(['gc_id'=>$params['id'],'is_used'=>0])->update(['delete_time'=>time()]);
+
+            if(!$res2){
+                Db::rollback();
+                self::setError('删除礼品卡信息错误!');
+            }
+
+
+            // 提交事务
+            Db::commit();
+            return true;
+        } catch (\Exception $e) {
+            // 回滚事务
+            Db::rollback();
+            return $e->getMessage();
+        }
+    }
+    /**
+     * @notes 删除礼品卡信息
+     * @param $params
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @author ljj
+     * @date 2022/3/31 2:37 下午
+     */
+    public function deleteGiftCardInfo($params)
+    {
+        Db::startTrans();
+        try {
+
+            $res = GiftCardInfo::destroy($params['id']);
+
+            if(!$res){
+                Db::rollback();
+                self::setError('删除礼品卡信息错误!');
+            }
+            // 提交事务
+            Db::commit();
+            return true;
+        } catch (\Exception $e) {
+            // 回滚事务
+            Db::rollback();
+            return $e->getMessage();
+        }
+    }
+}

+ 78 - 0
app/adminapi/validate/gift_card/GiftCardValidate.php

@@ -0,0 +1,78 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeshop开源商城系统
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | gitee下载:https://gitee.com/likeshop_gitee
+// | github下载:https://github.com/likeshop-github
+// | 访问官网:https://www.likeshop.cn
+// | 访问社区:https://home.likeshop.cn
+// | 访问手册:http://doc.likeshop.cn
+// | 微信公众号:likeshop技术社区
+// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
+// |  likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
+// | 禁止对系统程序代码以任何目的,任何形式的再发布
+// | likeshop团队版权所有并拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeshop.cn.team
+// +----------------------------------------------------------------------
+
+namespace app\adminapi\validate\gift_card;
+
+use app\common\model\GiftCard;
+use app\common\model\GiftCardInfo;
+use app\common\validate\BaseValidate;
+
+class GiftCardValidate extends BaseValidate
+{
+    protected $rule = [
+        'id' => 'require',
+        'num' => 'require',
+        'money' => 'require',
+
+    ];
+
+    protected $message = [
+        'id.require' => 'id参数缺失',
+        'num.require'   => '生成数量必填!',
+        'money.require'       => '礼品卡券价值必传',
+    ];
+
+
+    public function sceneAdd()
+    {
+        return $this->only(['num','money']);
+    }
+    public function sceneDetail()
+    {
+        return $this->only(['id'])
+            ->append('id','checkID');;
+    }
+
+    public function sceneDelGiftCard()
+    {
+        return $this->only(['id'])->append('id','checkID');;;
+    }
+    public function sceneDelGiftCardInfo()
+    {
+        return $this->only(['id'])->append('id','checkCardID');;;
+    }
+
+    public function checkID($value,$rule,$data){
+        $result = GiftCard::findOrEmpty($value);
+        if ($result->isEmpty()) {
+            return '批次信息不存在';
+        }
+        return true;
+    }
+
+    public function checkCardID($value,$rule,$data){
+        $result = GiftCardInfo::findOrEmpty($value);
+        if ($result->isEmpty()) {
+            return '礼品卡信息不存在';
+        }
+        return true;
+    }
+
+
+}

+ 13 - 0
app/common.php

@@ -30,6 +30,19 @@ function create_token(string $extra = ''): string
     return md5($extra . time().uniqid('likeshop'));
 }
 
+function gift_card_pass(){
+    $time = date('y').date('m').date('d').getNonceStr(6);
+    return str_shuffle($time);
+}
+
+function getNonceStr($length = 32) {
+    $chars = "ACEFGHMNQRTYabdefgijmnpqr";
+    $str ="";
+    for ( $i = 0; $i < $length; $i++ )  {
+        $str .= substr($chars, mt_rand(0, strlen($chars)-1), 1);
+    }
+    return $str;
+}
 /**
  * @notes 截取某字符字符串
  * @param $str

+ 56 - 0
app/common/model/GiftCard.php

@@ -0,0 +1,56 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeshop开源商城系统
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | gitee下载:https://gitee.com/likeshop_gitee
+// | github下载:https://github.com/likeshop-github
+// | 访问官网:https://www.likeshop.cn
+// | 访问社区:https://home.likeshop.cn
+// | 访问手册:http://doc.likeshop.cn
+// | 微信公众号:likeshop技术社区
+// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
+// |  likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
+// | 禁止对系统程序代码以任何目的,任何形式的再发布
+// | likeshop团队版权所有并拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeshop.cn.team
+// +----------------------------------------------------------------------
+
+namespace app\common\model;
+
+use app\common\enum\IntegralGoodsEnum;
+use app\common\enum\IntegralOrderEnum;
+use app\common\enum\PayEnum;
+use app\common\service\RegionService;
+use think\model\concern\SoftDelete;
+
+/**
+ * 积分订单模型
+ * Class IntegralOrder
+ * @package app\common\model
+ */
+class GiftCard extends BaseModel
+{
+    use SoftDelete;
+
+    protected $deleteTime = 'delete_time';
+
+    // 设置json类型字段
+    protected $json = ['goods_snap', 'address'];
+
+    // 设置JSON数据返回数组
+//    protected $jsonAssoc = true;
+
+    /**
+     * @notes 关联用户模型
+     * @return \think\model\relation\HasOne
+     * @author ljj
+     * @date 2022/3/30 5:16 下午
+     */
+    public function user()
+    {
+        return $this->hasOne(User::class, 'id', 'user_id')
+            ->field('id,sn,nickname,avatar,level,mobile,sex,create_time');
+    }
+}

+ 69 - 0
app/common/model/GiftCardInfo.php

@@ -0,0 +1,69 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeshop开源商城系统
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | gitee下载:https://gitee.com/likeshop_gitee
+// | github下载:https://github.com/likeshop-github
+// | 访问官网:https://www.likeshop.cn
+// | 访问社区:https://home.likeshop.cn
+// | 访问手册:http://doc.likeshop.cn
+// | 微信公众号:likeshop技术社区
+// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
+// |  likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
+// | 禁止对系统程序代码以任何目的,任何形式的再发布
+// | likeshop团队版权所有并拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeshop.cn.team
+// +----------------------------------------------------------------------
+
+namespace app\common\model;
+
+use app\common\enum\IntegralGoodsEnum;
+use app\common\enum\IntegralOrderEnum;
+use app\common\enum\PayEnum;
+use app\common\service\RegionService;
+use think\model\concern\SoftDelete;
+
+/**
+ * 积分订单模型
+ * Class IntegralOrder
+ * @package app\common\model
+ */
+class GiftCardInfo extends BaseModel
+{
+    use SoftDelete;
+
+    protected $deleteTime = 'delete_time';
+
+    // 设置JSON数据返回数组
+//    protected $jsonAssoc = true;
+
+    /**
+     * @notes 关联用户模型
+     * @return \think\model\relation\HasOne
+     * @author ljj
+     * @date 2022/3/30 5:16 下午
+     */
+    public function user()
+    {
+        return $this->hasOne(User::class, 'id', 'user_id')
+            ->field('id,sn,nickname,avatar,real_name,mobile,sex,create_time');
+    }
+
+    /**
+     * @notes 使用状态
+     * @param $value
+     * @param $data
+     * @return string|string[]
+     * @author ljj
+     * @date 2022/3/30 5:38 下午
+     */
+    public function getIsUsedDescAttr($value, $data)
+    {
+        return $data['is_used'] ? '已使用' : '未使用';
+
+    }
+
+
+}