From 794aaf0abde63ab88a9420c6491ae596040cd707 Mon Sep 17 00:00:00 2001 From: wangxinglong <2371974647@qq.com> Date: Wed, 24 Nov 2021 16:34:56 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=90=8E=E5=A4=A9=E4=BC=98=E6=83=A0?= =?UTF-8?q?=E5=88=B8=E5=88=97=E8=A1=A8=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/manager/Coupon.php | 48 +++++++- app/model/Coupon.php | 9 ++ app/model/CouponMain.php | 4 + app/repository/CouponRepository.php | 26 ++++- public/static/manager/js/consumer/info.js | 1 - public/static/manager/js/coupon/index.js | 23 ++++ public/static/manager/js/coupon/info.js | 19 +-- view/manager/coupon/index.html | 4 +- view/manager/coupon/info.html | 136 +++++++++++++--------- 9 files changed, 199 insertions(+), 71 deletions(-) diff --git a/app/controller/manager/Coupon.php b/app/controller/manager/Coupon.php index 764de30..1397ee8 100644 --- a/app/controller/manager/Coupon.php +++ b/app/controller/manager/Coupon.php @@ -90,10 +90,54 @@ class Coupon extends Base return $this->json(4001, "优惠券不存在"); } - if (in_array($on_shelf, [CouponMain::COMMON_OFF, CouponMain::COMMON_ON])) { + if (!in_array($on_shelf, [CouponMain::COMMON_OFF, CouponMain::COMMON_ON])) { return $this->json(4001, "状态错误"); } - $coupon->save(["on_shelf"=>$on_shelf]); + $coupon->save(["on_shelf" => $on_shelf]); return $this->json(); } + + /** + * 列表 + * + * @return Json|View + * @throws Exception + */ + public function info() + { + + if ($this->request->isPost()) { + $model = new CouponMain(); + $repo = CouponRepository::getInstance($model); + $id = input("id/d"); + $keyword = $this->request->param('keyword/s', ''); + $page = $this->request->param('page/d', 1); + $size = $this->request->param('size/d', 30); + + $list = $repo->couponMainHasList($id, $keyword, $page, $size); + $time = time(); + $list["list"]->each(function ($item) use ($time) { + if (strtotime($item['end_time']) < $time) { + $item->time_state = '已过期'; + } else { + $item->time_state = '未过期'; + } + + }); + return $this->json(0, 'success', $list); + } + $id = input("id/d"); + $model = new CouponMain(); + $repo = CouponRepository::getInstance($model); + $coupon = $repo->getModel()->with(["business" => function ($query) { + $query->field("code,business_name,business_subtitle,type") + ->with('category'); + }, "couponType"])->where("id", $id)->find(); + if (empty($coupon)) { + return $this->error("优惠券不存在"); + } + $this->data["coupon"] = $coupon; + return $this->view(); + } + } \ No newline at end of file diff --git a/app/model/Coupon.php b/app/model/Coupon.php index 553f34b..a5a7c80 100644 --- a/app/model/Coupon.php +++ b/app/model/Coupon.php @@ -23,4 +23,13 @@ class Coupon extends Base { return $this->hasOne(CouponBill::class,"coupon_id","id"); } + public function account() + { + return $this->hasOne(Account::class,"user_code","consumer_code"); + } + + public function business() + { + return $this->hasOne(Business::class,"code","business_code"); + } } \ No newline at end of file diff --git a/app/model/CouponMain.php b/app/model/CouponMain.php index ec114f2..9333cd2 100644 --- a/app/model/CouponMain.php +++ b/app/model/CouponMain.php @@ -23,4 +23,8 @@ class CouponMain extends Base { return $this->hasOne(Business::class, 'code',"business_code"); } + public function couponType() + { + return $this->hasOne(CouponType::class, 'id',"type_id"); + } } \ No newline at end of file diff --git a/app/repository/CouponRepository.php b/app/repository/CouponRepository.php index bbe516a..ec0b21c 100644 --- a/app/repository/CouponRepository.php +++ b/app/repository/CouponRepository.php @@ -3,6 +3,7 @@ namespace app\repository; use app\exception\RepositoryException; +use app\model\Coupon; use app\model\CouponMain; use app\service\Repository; use think\Model; @@ -17,16 +18,29 @@ use think\Model; class CouponRepository extends Repository { /** - * 优惠券列表 + * 优惠券持有信息列表 * - * @param string $businessCode 商家code - * @param array $order + * @param $id + * @param $keyword + * @param $page + * @param $size * @return array - * @throws RepositoryException + * @throws \Exception */ - public function businessCouponModel($where) + public function couponMainHasList($id, $keyword, $page, $size) { - return CouponMain::where($where); + + return Coupon::findList(["id" => $id], [], $page, $size, function ($q) use ($keyword) { + if (!empty($keyword)) { + return $q::hasWhere('account', function ($q) use ($keyword) { + $q->where('nick_name', 'like', "%" . $keyword . "%")->field("nick_name,avatar_url"); + }); + } else { + return $q->with(["account" => function ($query) { + $query->field("nick_name,avatar_url"); + }]); + } + }, ["id" => "desc"]); } } \ No newline at end of file diff --git a/public/static/manager/js/consumer/info.js b/public/static/manager/js/consumer/info.js index a06ccd3..8f784a3 100644 --- a/public/static/manager/js/consumer/info.js +++ b/public/static/manager/js/consumer/info.js @@ -42,7 +42,6 @@ layui.use(['laytpl', 'table', 'jquery', 'form', 'miniTab', 'xmSelect'], function {templet: '#row-received_map', title: '领取位置'}, {field: 'money', title: '金额'}, {field: 'business_name', title: '商家名称'}, - {field: 'business_name', title: '商家名称'}, {templet: '#row-sign_map', title: '签到位置'}, {templet: '#row-state', title: '状态'}, ]], diff --git a/public/static/manager/js/coupon/index.js b/public/static/manager/js/coupon/index.js index e0bc76f..f3db3c1 100644 --- a/public/static/manager/js/coupon/index.js +++ b/public/static/manager/js/coupon/index.js @@ -92,7 +92,30 @@ layui.use(['laytpl', 'table', 'jquery', 'form', 'miniTab', 'xmSelect','laydate'] elem: '#end_time' ,type: 'date' }); + //监听工具条 + table.on('tool(table-container)', function (obj) { + let data = obj.data; + let layEvent = obj.event; + let url = $($(this).context).data('href'); + let title = $($(this).context).data('title'); + let width = $($(this).context).data('width') ? $($(this).context).data('width') : '100%'; + let height = $($(this).context).data('height') ? $($(this).context).data('height') : '100%'; + let insTb = Tools.getInsTb(); + if (layEvent === 'shelf') { + $.post(url, null, function (res) { + layer.msg(res.msg) + if (res.code === 0) { + insTb.reload(); + } + }) + return false; + } + if (layEvent === 'info') { + openLayer(url, title, width, height); + return false; + } + }); } /*** index end ***/ diff --git a/public/static/manager/js/coupon/info.js b/public/static/manager/js/coupon/info.js index a06ccd3..08599d1 100644 --- a/public/static/manager/js/coupon/info.js +++ b/public/static/manager/js/coupon/info.js @@ -37,14 +37,19 @@ layui.use(['laytpl', 'table', 'jquery', 'form', 'miniTab', 'xmSelect'], function cols: [[ // {type: 'checkbox'}, {field: 'id' , width: 80, title: 'ID'}, - {field: 'name', title: '名称'}, - {field: 'type_name', title: '优惠券类型'}, - {templet: '#row-received_map', title: '领取位置'}, - {field: 'money', title: '金额'}, - {field: 'business_name', title: '商家名称'}, - {field: 'business_name', title: '商家名称'}, - {templet: '#row-sign_map', title: '签到位置'}, + {templet: '#row-cover', title: '头像'}, + {templet:function(d){ + if(d.account!=undefined&&d.account){ + return d.account.nick_name; + } + return d.consumer_name; + }, title: '昵称'}, + + {field: 'received_time', title: '领取时间'}, + + {templet: '#row-state', title: '状态'}, + {field: 'verificate_time', title: '验证时间'}, ]], done: function () { Tools.setInsTb(insTb); diff --git a/view/manager/coupon/index.html b/view/manager/coupon/index.html index 0e8091f..40533b8 100644 --- a/view/manager/coupon/index.html +++ b/view/manager/coupon/index.html @@ -87,7 +87,7 @@ @@ -130,5 +154,11 @@ + + - \ No newline at end of file + \ No newline at end of file From a8e09eff85c1f06a0753bbcbc097383805575a12 Mon Sep 17 00:00:00 2001 From: wangxinglong <2371974647@qq.com> Date: Thu, 25 Nov 2021 18:11:50 +0800 Subject: [PATCH 2/2] setter --- app/controller/manager/Agency.php | 270 ++++++++++++++++++ app/controller/manager/Bill.php | 38 +++ app/controller/manager/Business.php | 71 ++--- app/controller/manager/Config.php | 28 ++ app/controller/manager/Coupon.php | 158 +++++++++- app/controller/manager/Login.php | 1 - app/model/Member.php | 4 +- app/repository/BillRepository.php | 56 ++++ app/repository/BusinessRepository.php | 33 ++- app/repository/CouponRepository.php | 32 ++- app/validate/CouponRelease.php | 45 +++ public/static/manager/js/agency.js | 105 +++++++ public/static/manager/js/bill.js | 69 +++++ .../manager/js/business/business_wait_list.js | 48 +++- public/static/manager/js/coupon/index.js | 15 + view/manager/agency/add.html | 58 ++++ view/manager/agency/edit.html | 52 ++++ view/manager/agency/index.html | 58 ++++ view/manager/agency/password.html | 35 +++ view/manager/bill/index.html | 66 +++++ view/manager/business/business_wait_list.html | 7 +- .../config/distribution_proportion.html | 47 +++ view/manager/coupon/add.html | 173 +++++++++++ view/manager/coupon/edit.html | 174 +++++++++++ view/manager/coupon/index.html | 2 + 25 files changed, 1591 insertions(+), 54 deletions(-) create mode 100644 app/controller/manager/Agency.php create mode 100644 app/controller/manager/Bill.php create mode 100644 app/repository/BillRepository.php create mode 100644 app/validate/CouponRelease.php create mode 100644 public/static/manager/js/agency.js create mode 100644 public/static/manager/js/bill.js create mode 100644 view/manager/agency/add.html create mode 100644 view/manager/agency/edit.html create mode 100644 view/manager/agency/index.html create mode 100644 view/manager/agency/password.html create mode 100644 view/manager/bill/index.html create mode 100644 view/manager/config/distribution_proportion.html create mode 100644 view/manager/coupon/add.html create mode 100644 view/manager/coupon/edit.html diff --git a/app/controller/manager/Agency.php b/app/controller/manager/Agency.php new file mode 100644 index 0000000..4cdd530 --- /dev/null +++ b/app/controller/manager/Agency.php @@ -0,0 +1,270 @@ +request->isPost()) { + $item = input('post.'); + + $validate = $this->validateByApi($item, [ + 'username|用户名' => 'require|alphaDash|min:4|max:16|unique:member', + 'mobile|手机号' => 'require|unique:member', + 'nickname|昵称' => 'require|chsAlphaNum|min:2|max:10', + 'password|密码' => 'require|min:4|max:16', + 'remark|备注信息' => 'max:255', + ]); + + if ($validate !== true) { + return $validate; + } + + if (!checkMobile($item['mobile'])) { + return $this->json(4002, '请输入正确的手机号码'); + } + + $item['roles'] = [Member::ANENT_ROLE_ID]; + $item['status'] = Member::COMMON_ON; + + $roles = []; + if ($item['roles']) { + $roles = $item['roles']; + $item['roles'] = implode(',', $item['roles']); + } + + Db::startTrans(); + try { + + //如果关联商家 + if (!empty($item['business_code'])) { + $Business = BusinessRepository::getInstance()->findOneByWhere(["code" => $item['business_code']]); + if (empty($Business)) { + Db::rollback(); + return $this->json(4001, "指定商家不存在"); + } + $Business->save(["is_agency" => BusinessModel::COMMON_ON]); + } + + + $item['password'] = md5($item['password'] . $item['username']); + $member = MemberModel::create($item); + foreach ($roles as $role) { + Enforcer::addRoleForUser($member['id'], $role); + } + Db::commit(); + return $this->json(); + } catch (ValidateException $e) { + Db::rollback(); + return $this->json(4001, $e->getError()); + } + } + + $this->data['roleJson'] = $this->roleJson(); + $this->data['business'] = BusinessRepository::getInstance()->getBusinessAll(); + + return $this->view(); + } + + /** + * 编辑 + * + * @return Json|View + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + * @throws Exception + */ + public function edit() + { + $id = input('id/d', 0); + + if (!$info = MemberModel::findById($id)) { + return $this->json(4001, '记录不存在'); + } + + if ($this->request->isPost()) { + $item = input('post.'); + + $validate = $this->validateByApi($item, [ + 'mobile|手机号' => 'require|unique:member,mobile,' . $id, + 'nickname|昵称' => 'require|chsAlphaNum|min:2|max:10', + 'remark|备注信息' => 'max:255', + ]); + + if ($validate !== true) { + return $validate; + } + + if (!checkMobile($item['mobile'])) { + return $this->json(4002, '请输入正确的手机号码'); + } + $item['roles'] = [Member::ANENT_ROLE_ID]; + $roles = []; + if ($item['roles']) { + $roles = $item['roles']; + $item['roles'] = implode(',', $item['roles']); + } + + + Db::startTrans(); + try { + //之前关联的商家不为空 并且已经改变 吧之前的商家 从代理商变成普通商家 + if ($info['business_code'] != $item['business_code']) { + if (!empty($info['business_code'])) { + $oldBusiness = BusinessRepository::getInstance()->findOneByWhere(["code" => $info['business_code']]); + if (!empty($oldBusiness)) { + $oldBusiness->save(["is_agency" => BusinessModel::COMMON_OFF]); + } + } + //如果改变了关联商家 + if (!empty($item['business_code'])) { + $Business = BusinessRepository::getInstance()->findOneByWhere(["code" => $item['business_code']]); + if (empty($Business)) { + Db::rollback(); + return $this->json(4001, "指定商家不存在"); + } + $Business->save(["is_agency" => BusinessModel::COMMON_ON]); + } + } + + $info->save($item); + //删除所有角色 + Enforcer::deleteRolesForUser($id); + //新增角色 + foreach ($roles as $role) { + Enforcer::addRoleForUser($id, $role); + } + Db::commit(); + return $this->json(); + } catch (ValidateException $e) { + Db::rollback(); + return $this->json(4001, $e->getError()); + } + } + + $this->data['item'] = $info; + $this->data['roleJson'] = $this->roleJson(explode(',', $info['roles'])); + + $this->data['business'] = BusinessRepository::getInstance()->getBusinessAll(); + + return $this->view(); + } + + + /** + * 轮播图列表 + * + * @return Json|View + * @throws Exception + */ + public function index() + { + + if ($this->request->isPost()) { + $page = $this->request->param('page/d', 1); + $size = $this->request->param('size/d', 30); + + //只查询拥有渠道商的账号 + $whereMap = [['roles', "=", Member::ANENT_ROLE_ID], ['id', "<>", 1]]; + $orders = ['id' => 'asc']; + + $list = Member::findList($whereMap, [], $page, $size, null, $orders); + + return $this->json(0, 'success', $list); + } + return $this->view(); + } + + + /** + * 删除 + * + * @return Json + */ + public function del(): Json + { + if ($this->request->isPost()) { + $ids = input('post.ids/a', []); + if (empty($ids)) { + $ids[] = input('post.id/d'); + } + MemberModel::deleteByIds($ids); + foreach ($ids as $id) { + Enforcer::deleteRolesForUser($id); + } + Log::write(get_class() . 'Del', 'del', '涉及到的ID为:' . implode(',', $ids)); + return $this->json(); + } + return $this->json(4001, '非法请求!'); + } + + + /** + * 修改密码 + * + * @return Json|View|Redirect + * @throws Exception + */ + public function password() + { + $id = input('id/d', 0); + + if (!$item = MemberModel::findById($id)) { + if ($this->request->isAjax()) { + return $this->json(4001, '记录不存在'); + } + return $this->error('记录不存在'); + } + + if ($this->request->isPost()) { + $post = input('post.'); + $validate = $this->validateByApi($post, [ + 'password|密码' => 'require|confirm', + ]); + + if ($validate !== true) { + return $validate; + } + + $password = md5($post['password'] . $item['username']); + + try { + $item->save(['password' => $password]); + return $this->json(); + } catch (ValidateException $e) { + return $this->json(4001, $e->getError()); + } + } + + $this->data['item'] = $item; + + return $this->view(); + } + +} \ No newline at end of file diff --git a/app/controller/manager/Bill.php b/app/controller/manager/Bill.php new file mode 100644 index 0000000..8de5928 --- /dev/null +++ b/app/controller/manager/Bill.php @@ -0,0 +1,38 @@ +request->isPost()) { + $repo = BillRepository::getInstance(); + $keyword = $this->request->param('keyword/s', ''); + $page = $this->request->param('page/d', 1); + $size = $this->request->param('size/d', 30); + $orders = ['sort'=>'asc']; + + + $list = $repo->billList($keyword, $page, $size, $orders); + + return $this->json(0, 'success', $list); + } + + return $this->view(); + } + + +} \ No newline at end of file diff --git a/app/controller/manager/Business.php b/app/controller/manager/Business.php index d358330..c808d54 100644 --- a/app/controller/manager/Business.php +++ b/app/controller/manager/Business.php @@ -234,6 +234,7 @@ class Business extends Base if ($this->request->isPost()) { $businessCode = input("business_code/s", ""); $state = input("state/d", 0); + $reason = input("reason/s", ''); $business = BusinessRepository::getInstance()->findOneByWhere(["code" => $businessCode]); if (empty($business)) { return $this->json(4001, "商家不存在"); @@ -246,15 +247,15 @@ class Business extends Base } Db::startTrans(); try { - $business->save(["state"=>$state]); + $business->save(["state" => $state, "reason" => $reason]); Db::commit(); - return $this->json(); - }catch (RepositoryException $e){ + return $this->json(); + } catch (RepositoryException $e) { Db::rollback(); - return $this->json("5001","审核失败"); - }catch (\think\Exception $e){ + return $this->json("5001", "审核失败"); + } catch (\think\Exception $e) { Db::rollback(); - return $this->json("5002","审核失败"); + return $this->json("5002", "审核失败"); } } } @@ -272,24 +273,24 @@ class Business extends Base if ($this->request->isPost()) { $anent_code = input("agency_code/s", ""); - if(empty($business)){ - return $this->json(4001,"商家不存在"); + if (empty($business)) { + return $this->json(4001, "商家不存在"); } Db::startTrans(); try { - $business->save(["agency_code"=>$anent_code]); + $business->save(["agency_code" => $anent_code]); Db::commit(); - return $this->json(); - }catch (RepositoryException $e){ + return $this->json(); + } catch (RepositoryException $e) { Db::rollback(); - return $this->json("5001","指派失败"); - }catch (\think\Exception $e){ + return $this->json("5001", "指派失败"); + } catch (\think\Exception $e) { Db::rollback(); - return $this->json("5002","指派失败"); + return $this->json("5002", "指派失败"); } } - if(empty($business)){ - return $this->error("商家不存在"); + if (empty($business)) { + return $this->error("商家不存在"); } $this->data["agent"] = Member::getAgentAll(); $this->data["businessCode"] = $businessCode; @@ -308,47 +309,47 @@ class Business extends Base $business = BusinessRepository::getInstance()->findOneByWhere(["code" => $businessCode]); if ($this->request->isPost()) { - $money = input("money/f", 0,"abs"); - if($money<=0){ - return $this->json(4001,"金额错误"); + $money = input("money/f", 0, "abs"); + if ($money <= 0) { + return $this->json(4001, "金额错误"); } $money = floor($money * 100) / 100; - if(empty($business)){ - return $this->json(4001,"商家不存在"); + if (empty($business)) { + return $this->json(4001, "商家不存在"); } Db::startTrans(); try { //创建充值订单 - if (!$order = RechargeRepository::getInstance()->createOrder($businessCode,$money)) { + if (!$order = RechargeRepository::getInstance()->createOrder($businessCode, $money)) { throw new RepositoryException('订单创建失败,请稍后重试'); } //生成支付 $res = WechatPay::getInstance()->order->unify([ - 'body' => '商家充值', + 'body' => '商家充值', 'out_trade_no' => $order->order_num, - 'total_fee' => $money * 100, - 'trade_type' => 'NATIVE', - 'product_id' => $order->id, - 'notify_url' => $this->request->domain()."/api/recharge/notify.html", + 'total_fee' => $money * 100, + 'trade_type' => 'NATIVE', + 'product_id' => $order->id, + 'notify_url' => $this->request->domain() . "/api/recharge/notify.html", ]); - if(!isset($res['code_url'])){ + if (!isset($res['code_url'])) { throw new RepositoryException('订单创建失败,请稍后重试'); } Db::commit(); - return $this->json(0,"success",["order_num"=>$order->order_num,"code_url"=>$res['code_url']]); - }catch (RepositoryException $e){ + return $this->json(0, "success", ["order_num" => $order->order_num, "code_url" => $res['code_url']]); + } catch (RepositoryException $e) { Db::rollback(); - return $this->json("5001",$e->getMessage()); - }catch (Exception $e){ + return $this->json("5001", $e->getMessage()); + } catch (Exception $e) { Db::rollback(); - return $this->json("5001",$e->getMessage()); + return $this->json("5001", $e->getMessage()); } } - if(empty($business)){ - return $this->error("商家不存在"); + if (empty($business)) { + return $this->error("商家不存在"); } $this->data["businessCode"] = $businessCode; diff --git a/app/controller/manager/Config.php b/app/controller/manager/Config.php index 3bc3871..cb0371d 100644 --- a/app/controller/manager/Config.php +++ b/app/controller/manager/Config.php @@ -182,4 +182,32 @@ class Config extends Base return $this->view('manager/config/'.$name); } } + + /* 分配比例*/ + public function distributionProportion(){ + if ($this->request->isPost()) { + $data = input("post."); + unset($data['_token']); + $validate = $this->validateByApi($data, [ + 'agency' => 'require|number', + 'admin' => 'require|number', + 'consumer' => 'require|number', + ]); + + if ($validate !== true) { + return $validate; + } + $total = $data['agency'] + $data['admin'] + $data['consumer']; + if ($total != 100) { + return $this->json(5002,"分配比例总和不等于100"); + } + $php = var_export($data, true); + file_put_contents($this->extraPath . 'distribution_proportion.php', 'json(); + } else { + CConfig::load('extra/distribution_proportion', 'distributionProportion'); + $this->data['item'] = config('distributionProportion'); + return $this->view(); + } + } } \ No newline at end of file diff --git a/app/controller/manager/Coupon.php b/app/controller/manager/Coupon.php index 1397ee8..c253fe7 100644 --- a/app/controller/manager/Coupon.php +++ b/app/controller/manager/Coupon.php @@ -5,11 +5,14 @@ namespace app\controller\manager; use app\exception\RepositoryException; use app\model\CouponMain; +use app\repository\BusinessRepository; use app\repository\CouponRepository; +use app\validate\CouponRelease; use Exception; use think\facade\Db; use think\response\Json; use think\response\View; +use think\facade\Config as CConfig; /** * 优惠券相关 @@ -17,6 +20,13 @@ use think\response\View; class Coupon extends Base { + protected function initialize() + { + parent::initialize(); // TODO: Change the autogenerated stub + CConfig::load('extra/distribution_proportion', 'distributionProportion'); + $this->data['distributionProportion'] = config('distributionProportion'); + } + /** * 列表 * @@ -98,7 +108,7 @@ class Coupon extends Base } /** - * 列表 + * 持有详细 * * @return Json|View * @throws Exception @@ -130,7 +140,8 @@ class Coupon extends Base $model = new CouponMain(); $repo = CouponRepository::getInstance($model); $coupon = $repo->getModel()->with(["business" => function ($query) { - $query->field("code,business_name,business_subtitle,type") + $query + ->field("code,business_name,business_subtitle,type") ->with('category'); }, "couponType"])->where("id", $id)->find(); if (empty($coupon)) { @@ -140,4 +151,147 @@ class Coupon extends Base return $this->view(); } + /** + * 发布优惠券 + * + * @return Json|View + * @throws Exception + */ + + public function release() + { + if ($this->request->isPost()) { + $data = input("item/a", []); + $validate = new CouponRelease(); + if (!$validate->check($data)) { + return $this->json(4001, $validate->getError()); + } + $business = BusinessRepository::getInstance()->getBusinessAccount($data["business_code"], true); + + if (empty($business)) { + return $this->json(4001, '商家不存在'); + } + $data['business_type'] = $business->business['type']; + $data['business_name'] = $business->business['business_name']; + $data['lng'] = $business->business['lng']; + $data['lat'] = $business->business['lat']; + + + $type = CouponRepository::getInstance()->getCouponTypeAll(); + $type = array_column($type->toArray(), null, "id"); + if (!isset($type[$data['type']])) { + return $this->json(4001, '优惠券类型不存在'); + } + $data['commission_agency'] = input("item.commission_agency/d", 0); + $data['commission_admin'] = input("item.commission_admin/d", 0); + $data['commission_consumer'] = input("item.commission_consumer/d", 0); + + $totalC = $data['commission_agency'] + $data['commission_admin'] + $data['commission_consumer']; + if ($totalC != 100) { + return $this->json(5002, "分配比例总和不等于100"); + } + + //保留两位小数 + $data['money'] = floor($data['money'] * 100) / 100; + + $totalMoney = $data['money'] * $data['count']; + if ($business->business["balance"] < $totalMoney) { + return $this->json(4001, '商家余额不足'); + } + + $data['type_name'] = $type[$data['type']]['name']; + $date = date("Y-m-d H:i:s"); + $data['create_time'] = $date; + $data['update_time'] = $date; + + Db::startTrans(); + try { + CouponRepository::getInstance()->releaseCouponMain($data, $totalMoney); + Db::commit(); + return $this->json(); + } catch (RepositoryException $e) { + Db::rollback(); + return $this->json(5001, "发布失败" . $e->getMessage()); + } catch (\think\Exception $e) { + Db::rollback(); + return $this->json(5002, "发布失败" . $e->getMessage()); + } + + } + + + $this->data['business'] = BusinessRepository::getInstance()->getBusinessAll(); + $this->data['type'] = CouponRepository::getInstance()->getCouponTypeAll(); + return $this->view('add'); + + } + + /** + * 修改 + * + * @return Json|View + * @throws Exception + */ + + public function edit() + { + $couponMain = CouponMain::findById(input("id/d", 0)); + if ($this->request->isPost()) { + $data = input("item/a", []); + + if (empty($couponMain)) { + return $this->json(4001, "优惠券不存在"); + } + $validate = new CouponRelease(); + if (!$validate->scene("edit")->check($data)) { + return $this->json(4001, $validate->getError()); + } + $business = BusinessRepository::getInstance()->getBusinessAccount($data["business_code"], true); + + if (empty($business)) { + return $this->json(4001, '商家不存在'); + } + //更新经纬度 + $data['business_type'] = $business->business['type']; + $data['business_name'] = $business->business['business_name']; + $data['lng'] = $business->business['lng']; + $data['lat'] = $business->business['lat']; + + + $data['commission_agency'] = input("item.commission_agency/d", 0); + $data['commission_admin'] = input("item.commission_admin/d", 0); + $data['commission_consumer'] = input("item.commission_consumer/d", 0); + $totalC = $data['commission_agency'] + $data['commission_admin'] + $data['commission_consumer']; + if ($totalC != 100) { + return $this->json(5002, "分配比例总和不等于100"); + } + + $data['update_time'] = date("Y-m-d H:i:s"); + + Db::startTrans(); + try { + $couponMain->save($data); + Db::commit(); + return $this->json(); + } catch (RepositoryException $e) { + Db::rollback(); + return $this->json(5001, "发布失败" . $e->getMessage()); + } catch (\think\Exception $e) { + Db::rollback(); + return $this->json(5002, "发布失败" . $e->getMessage()); + } + + } + + if (empty($couponMain)) { + return $this->error("优惠券不存在"); + } + $this->data['business'] = BusinessRepository::getInstance()->getBusinessAll(); + $this->data['type'] = CouponRepository::getInstance()->getCouponTypeAll(); + $this->data['item'] = $couponMain; + + return $this->view(); + + } + } \ No newline at end of file diff --git a/app/controller/manager/Login.php b/app/controller/manager/Login.php index 7c54522..4d080c5 100644 --- a/app/controller/manager/Login.php +++ b/app/controller/manager/Login.php @@ -46,7 +46,6 @@ class Login extends BaseController 'user_id' => $member['id'], 'username' => $member['username'], 'nickname' => $member['nickname'], - 'account_id' => $member['account_id'],//绑定的前台用户ID ]; $jwtToken = Jwt::generate($userInfo, env('app.expire', 7200)); diff --git a/app/model/Member.php b/app/model/Member.php index 529bb8f..a626080 100644 --- a/app/model/Member.php +++ b/app/model/Member.php @@ -9,7 +9,7 @@ class Member extends Base public const STATUS_NORMAL = 1;//正常 public const STATUS_DISABLE = 0;//禁用 - public const ANENT_role_id = 2;//角色id 2 为代理商 + public const ANENT_ROLE_ID = 2;//角色id 2 为代理商 @@ -29,7 +29,7 @@ class Member extends Base $subQuery = Db::name('member') ->field('id,business_code,nickname') - ->whereRaw('(find_in_set("'.Member::ANENT_role_id.'", roles))') + ->whereRaw('(find_in_set("'.Member::ANENT_ROLE_ID .'", roles))') ->buildSql(); return Db::table($subQuery . ' a') diff --git a/app/repository/BillRepository.php b/app/repository/BillRepository.php new file mode 100644 index 0000000..4bbad0a --- /dev/null +++ b/app/repository/BillRepository.php @@ -0,0 +1,56 @@ + "desc"]) + { + $failData = [ + 'total' => 0, + 'current' => $page, + 'size' => $size, + 'list' => new Collection(), + ]; + $rep = CouponBill::alias("a") + ->join("business b", "a.business_code = b.code") + ->wher(!empty($keyword), function ($q) use ($keyword) { + $q->where("b.business_name", "like", "%$keyword%"); + }); + + $failData ['total'] = $rep->count(); + $failData ['list'] = $rep->field("a.*,b.business_name") + ->page($page, $size) + ->order($orders) + ->select(); + return $failData; + } + + +} \ No newline at end of file diff --git a/app/repository/BusinessRepository.php b/app/repository/BusinessRepository.php index c3f9e81..93674c7 100644 --- a/app/repository/BusinessRepository.php +++ b/app/repository/BusinessRepository.php @@ -4,6 +4,7 @@ namespace app\repository; use app\exception\RepositoryException; use app\model\Business; +use app\model\BusinessFlow; use app\model\CouponMain; use app\model\Deduction; use app\model\Recharge; @@ -104,12 +105,34 @@ class BusinessRepository extends Repository */ public function businessRechargeList($where, int $page = 1, int $limit = 0, array $order = ["create_time" => "desc", "id" => "desc"]) { - return Recharge::findList($where, [], $page, $limit, function ($q){ - return $q->withJoin(["business"=>["business_name"]]); + return Recharge::findList($where, [], $page, $limit, function ($q) { + return $q->withJoin(["business" => ["business_name"]]); }, $order); } - /* 获取所有不是代理商的商家*/ - public function getBusinessAll(){ - return Business:: where("state", Business::state_on)->select(); + + /* 获取所有的商家*/ + public function getBusinessAll() + { + return Business:: where("state", Business::state_on)->select(); + } + + /** + * 获取单个商家详情 + * @param $businessCode + * @param bool $lock + * @return BusinessFlow|array|Model|null + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getBusinessAccount($businessCode,bool $lock = false) + { + $Flow = BusinessFlow::with(["account", "business"])->where("business_code", $businessCode)->when($lock,function ($q){ + $q->lock(true); + })->find(); + if (empty($Flow) || empty($Flow->account) || empty($Flow->business)) { + return null; + } + return $Flow; } } \ No newline at end of file diff --git a/app/repository/CouponRepository.php b/app/repository/CouponRepository.php index ec0b21c..83634e2 100644 --- a/app/repository/CouponRepository.php +++ b/app/repository/CouponRepository.php @@ -2,10 +2,12 @@ namespace app\repository; -use app\exception\RepositoryException; +use app\model\Business; use app\model\Coupon; use app\model\CouponMain; +use app\model\CouponType; use app\service\Repository; +use think\Db; use think\Model; /** @@ -43,4 +45,32 @@ class CouponRepository extends Repository }, ["id" => "desc"]); } + /** + * 优惠券持有信息列表 + * + * @param $id + * @param $keyword + * @param $page + * @param $size + * @return array + * @throws \Exception + */ + + public function getCouponTypeAll() + { + + return CouponType::order(["id" => "desc"])->select(); + } + + /** + * 发布优惠券 扣除商家余额 + * @param $data + * @param $totalMoney + */ + public function releaseCouponMain($data, $totalMoney) + { + CouponMain::create($data); + Business::where("code", $data["business_code"])->dec("balance", $totalMoney)->update(); + } + } \ No newline at end of file diff --git a/app/validate/CouponRelease.php b/app/validate/CouponRelease.php new file mode 100644 index 0000000..f61b7fa --- /dev/null +++ b/app/validate/CouponRelease.php @@ -0,0 +1,45 @@ + 'require', + //'lng|经度' => 'require', + //'lat|纬度' => 'require', + 'count|总数' => 'require|number|>:0', + 'type|优惠券类型' => 'require', + 'start_time|开始时间' => 'require|date', + 'end_time|结束时间' => 'require|date|checkEndTime', + 'name|优惠券名称' => 'require|length:3,32', + 'money|金额' => 'require|>:0|<:5000', +// 'deduction_money|扣除金额' => 'require|>=:0|<:5000', + //'image_url|预览图' => '', + //'using_rule|使用规则' => '', + //'punishing_rule|处罚规则' => '', + //'using_count|使用中' => '', + //'received_count|已领取的优惠券数量' => '', + //'edition|发布的版本' => '', + 'status|状态' => 'require|in:1,0', + 'on_shelf|上架状态' => 'require|in:1,0', + //'intro|详情' => '', + ]; + + + protected $scene = [ + 'edit' => ['start_time', 'end_time', 'name',"status","on_shelf"], + ]; + + protected function checkEndTime($value, $rule, $data = []) + { + if (strtotime($value) <= strtotime($data['start_time'])) { + return "结束时间不能小于等于开始时间"; + } + return true; + + } + +} \ No newline at end of file diff --git a/public/static/manager/js/agency.js b/public/static/manager/js/agency.js new file mode 100644 index 0000000..a8eac18 --- /dev/null +++ b/public/static/manager/js/agency.js @@ -0,0 +1,105 @@ +layui.use(['laytpl', 'table', 'jquery', 'form', 'miniTab', 'xmSelect'], function () { + let $ = layui.jquery, + form = layui.form, + table = layui.table, + layer = layui.layer, + xmSelect = layui.xmSelect, + miniTab = layui.miniTab; + + /**** index begin ***/ + //index页面 + if ($('.location-index-page').length > 0) { + miniTab.listen(); + + // 渲染表格 + let listUrl = $('#table-container').data('url'); + let insTb = table.render({ + elem: '#table-container', + toolbar: '#toolbar-tpl', + defaultToolbar: [null], + url: listUrl, + method: 'post', + even: true, + limits: [10,20,50,100,200,500,1000], + request: { + pageName: 'page', + limitName: 'size', + }, + parseData: function (res) { + return { + "code": res.code, //解析接口状态 + "msg": res.msg, //解析提示文本 + "count": res.data.total, //解析数据长度 + "data": res.data.list //解析数据列表 + }; + }, + page: true, + cols: [[ + {type: 'checkbox'}, + {field: 'id', width: 80, title: 'ID'}, + {field: 'nickname', minWidth: 200, title: '昵称'}, + {field: 'username', minWidth: 200, title: '用户名'}, + {field: 'mobile', minWidth: 200, title: '手机号'}, + {templet: '#row-status', minWidth: 200, title: '状态'}, + + {templet: '#row-operate', minWidth: 150, field: 'right', align: 'center', title: '操作', fixed: 'right'} + ]], + done: function () { + Tools.setInsTb(insTb); + } + }); + + // 监听搜索操作 + form.on('submit(data-search-btn)', function (data) { + //执行搜索重载 + table.reload('table-container', { + page: {curr: 1} + , where: data.field + }, 'data'); + + return false; + }); + + /** td edit **/ + + table.on('edit(table-container)', function (obj) { + let id = obj.data.id; + if (obj.field == 'sort') { + $.ajax('/manager/slide/sort', { + data: { + "sort": obj.value, + "id": id + } + ,dataType : 'json' + ,type: 'POST' + }) + .done(function () { + insTb.reload(); + }) + } + }); + } + /*** index end ***/ + + /** add and edit **/ + if ($('.location-operate-page').length > 0) { + //监听提交 + form.on('submit(saveMember)', function (data) { + let url = $(data.elem).data('url'); + $.post(url, data.field, function (res) { + layer.msg(res.msg); + if (res.code === 0) { + //刷新父级列表 + parent.layui.$('[data-table-refresh]').trigger("click"); + setTimeout(function () { + //关闭当前弹出层 + let iframeIndex = parent.layer.getFrameIndex(window.name); + parent.layer.close(iframeIndex); + }, 1000) + } + }); + return false; + }); + } + +}); \ No newline at end of file diff --git a/public/static/manager/js/bill.js b/public/static/manager/js/bill.js new file mode 100644 index 0000000..09e7c66 --- /dev/null +++ b/public/static/manager/js/bill.js @@ -0,0 +1,69 @@ +layui.use(['laytpl', 'table', 'jquery', 'form', 'miniTab', 'xmSelect'], function () { + let $ = layui.jquery, + form = layui.form, + table = layui.table, + layer = layui.layer, + xmSelect = layui.xmSelect, + miniTab = layui.miniTab; + + /**** index begin ***/ + //index页面 + if ($('.location-index-page').length > 0) { + miniTab.listen(); + + // 渲染表格 + let listUrl = $('#table-container').data('url'); + let insTb = table.render({ + elem: '#table-container', + toolbar: '#toolbar-tpl', + defaultToolbar: [{ //自定义头部工具栏右侧图标。如无需自定义,去除该参数即可 + title: '搜索' + , layEvent: 'search' + , icon: 'layui-icon-search' + }], + url: listUrl, + method: 'post', + even: true, + limits: [10,20,50,100,200,500,1000], + request: { + pageName: 'page', + limitName: 'size', + }, + parseData: function (res) { + return { + "code": res.code, //解析接口状态 + "msg": res.msg, //解析提示文本 + "count": res.data.total, //解析数据长度 + "data": res.data.list //解析数据列表 + }; + }, + page: true, + cols: [[ + {type: 'checkbox'}, + {field: 'id', width: 80, title: 'ID'}, + {field: 'title', minWidth: 200, title: '标题'}, + + ]], + done: function () { + Tools.setInsTb(insTb); + } + }); + + // 监听搜索操作 + form.on('submit(data-search-btn)', function (data) { + //执行搜索重载 + table.reload('table-container', { + page: {curr: 1} + , where: data.field + }, 'data'); + + return false; + }); + + + + + } + /*** index end ***/ + +}); \ No newline at end of file diff --git a/public/static/manager/js/business/business_wait_list.js b/public/static/manager/js/business/business_wait_list.js index 02f9770..1cf0699 100644 --- a/public/static/manager/js/business/business_wait_list.js +++ b/public/static/manager/js/business/business_wait_list.js @@ -85,12 +85,48 @@ layui.use(['laytpl', 'table', 'jquery', 'form', 'miniTab', 'xmSelect'], function let title = $(obj.tr.context).data('title'); if (layEvent === 'wait') { - $.post(url, {}, function (res) { - layer.msg(res.msg); - if (res.code === 0) { - insTb.reload(); - } - }) + state= $($(this).context).data('state') ; + + if(state == 1){ + $.post(url, {state:state}, function (res) { + layer.msg(res.msg); + if (res.code === 0) { + insTb.reload(); + } + }) + }else{ + layer.open({ + id:1, + type: 1, + title:'驳回请求', + skin:'layui-layer-rim', + area:['450px', '250px'], + + content: '