From 4daeae6f3406d01d19d740b743ee5136e9092260 Mon Sep 17 00:00:00 2001 From: wangxinglong <2371974647@qq.com> Date: Wed, 22 Dec 2021 18:50:19 +0800 Subject: [PATCH] setter --- app/controller/api/Consumer.php | 2 +- app/controller/manager/Agency.php | 26 +++++++++++++++++--------- app/controller/manager/Bill.php | 2 +- app/repository/BillRepository.php | 17 +++++++++++++---- app/repository/BusinessRepository.php | 2 +- app/validate/BusinessValidate.php | 4 ++-- app/validate/CouponRelease.php | 2 +- view/manager/agency/edit_channel.html | 2 +- 8 files changed, 37 insertions(+), 20 deletions(-) diff --git a/app/controller/api/Consumer.php b/app/controller/api/Consumer.php index 73fb581..eec814d 100644 --- a/app/controller/api/Consumer.php +++ b/app/controller/api/Consumer.php @@ -53,7 +53,7 @@ class Consumer extends Base $lngRange = []; $latRange = []; $whereMap = []; - $sortOrder = ['square'=> 'asc', 'start_time'=>'asc']; + $sortOrder = ['square'=> 'asc', 'id'=>'desc']; $whereMap[] = ['status', '=', CouponMain::status_on]; $whereMap[] = ['on_shelf', '=', CouponMain::on_shelf_on]; diff --git a/app/controller/manager/Agency.php b/app/controller/manager/Agency.php index 7e85170..bf88441 100644 --- a/app/controller/manager/Agency.php +++ b/app/controller/manager/Agency.php @@ -206,6 +206,7 @@ class Agency extends Base 'mobile|手机号' => 'require|unique:member,mobile,' . $id, 'nickname|昵称' => 'require|chsAlphaNum|min:2|max:10', 'remark|备注信息' => 'max:255', + 'business_code|商家' => 'length:32', ]); if ($validate !== true) { @@ -220,24 +221,24 @@ class Agency extends Base try { //之前关联的商家不为空 并且已经改变 吧之前的商家 从代理商变成普通商家 if ($info['business_code'] != $item['business_code']) { - if($info['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($item['business_code']!="_"){ - $Business = BusinessRepository::getInstance()->findOneByWhere(["code" => $item['business_code']]); - if (empty($Business)) { + 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]); + $business->save(["is_agency" => BusinessModel::COMMON_ON]); } //修改下级工作人员的平台商号 - BusinessModel::where("pid",$info['id'])->update(["business_code"=>$item['business_code']]); + memberModel::where("pid",$info['id'])->update(["business_code"=>$item['business_code']]); } $info->save($item); @@ -389,13 +390,20 @@ class Agency extends Base if (empty($ids)) { $ids[] = input('post.id/d'); } - foreach ($ids as $id) { - if ($id == 1) { + + + $member = MemberModel::findList([["id","in",$ids]]); + foreach ($member as $item){ + if ($item->id == 1) { return $this->json(5000, "错误的删除操作"); } - if(MemberModel::hasStaff($id)){ + if(MemberModel::hasStaff($item->id)){ return $this->json(5000, "还存在员工,不能删除"); } + //修改对应的商家成普通商家 + if(!empty($item->business_code)){ + BusinessModel::where("code",$item->business_code)->update(["is_agency"=>BusinessModel::COMMON_OFF]); + } } MemberModel::deleteByIds($ids); foreach ($ids as $id) { diff --git a/app/controller/manager/Bill.php b/app/controller/manager/Bill.php index c3dde45..94dda25 100644 --- a/app/controller/manager/Bill.php +++ b/app/controller/manager/Bill.php @@ -81,7 +81,7 @@ class Bill extends Base public function deduction() { $startTime = input("start_time/s", date("Y-m-d H:i:s", strtotime(date("Y-m-d") . " -1 month"))); - $endTime = input("end_time/s", date("Y-m-d 00:00:00")); + $endTime = input("end_time/s", date("Y-m-d 23:59:59")); if ($this->request->isPost()) { $repo = BillRepository::getInstance(); $keyword = $this->request->param('keyword/s', ''); diff --git a/app/repository/BillRepository.php b/app/repository/BillRepository.php index 3fb5163..084b911 100644 --- a/app/repository/BillRepository.php +++ b/app/repository/BillRepository.php @@ -173,15 +173,14 @@ class BillRepository extends Repository ]; $rep = Deduction::alias("a") ->join("business c", "a.business_code = c.code") - ->join("business f", "f.code = c.agency_code", "left") ->join("coupon_main e", "a.coupon_main_id = e.id") ->join("coupon_bill d", "a.bill_id = d.id") - ->join("account b", "d.user_code = b.user_code", "left") + ->join("account b", "a.user_code = b.user_code") ->when(!empty($startTime), function ($q) use ($startTime) { $q->whereTime("a.create_time", ">=", $startTime); }) ->when(!empty($keyword), function ($q) use ($keyword) { - $q->where("c.business_name|f.business_name", "like", "%" . $keyword . "%"); + $q->where("c.business_name|e.name", "like", "%" . $keyword . "%"); }) ->when(!empty($endTime), function ($q) use ($endTime) { $q->whereTime("a.create_time", "<=", $endTime); @@ -195,7 +194,8 @@ class BillRepository extends Repository "b.avatar_url", "e.name as coupon_main_name", "c.business_name", - "f.business_name as agency_business_name", + "c.agency_code", + "d.consumer_money", "d.admin_money", @@ -212,6 +212,15 @@ class BillRepository extends Repository ->page($page, $size) ->order($orders) ->select(); + $failData["list"]->each(function ($item){ + if(empty($item->agency_code)){ + $item->agency_business_name = MemberModel::whereRaw("FIND_IN_SET('".MemberModel::ANENT_ROLE_ID."',roles)" ) + ->where("business_code",$item->agency_code)->value("nickname",""); + }else{ + $item->agency_business_name = ""; + } + + }); return $failData; } diff --git a/app/repository/BusinessRepository.php b/app/repository/BusinessRepository.php index 1ccabb2..a491dc7 100644 --- a/app/repository/BusinessRepository.php +++ b/app/repository/BusinessRepository.php @@ -43,7 +43,7 @@ class BusinessRepository extends Repository $q = $this->model->alias("a") ->join("account b", "a.code = b.business_code") ->join("category c", "a.type = c.id","left") - ->where("b.type","=",Account::type_business) + ->where("b.type","=",Account::type_consumer) ->field(["a.code as business_code", "b.avatar_url", "b.nick_name as account_nick_name", diff --git a/app/validate/BusinessValidate.php b/app/validate/BusinessValidate.php index 27a0be3..aa888c7 100644 --- a/app/validate/BusinessValidate.php +++ b/app/validate/BusinessValidate.php @@ -8,8 +8,8 @@ class BusinessValidate extends Validate { protected $rule = [ 'type' => 'require|gt:0', - 'business_name|商家名称' => 'require|max:150', - 'business_subtitle|商家简称' => 'require|max:150', + 'business_name|商家名称' => 'require|graph|max:150', + 'business_subtitle|商家简称' => 'require|graph|max:150', 'business_license|营业执照' => 'require|max:250', 'contact_name|联系人' => 'require|max:20', 'contact_phone|联系电话' => 'require|max:20', diff --git a/app/validate/CouponRelease.php b/app/validate/CouponRelease.php index a9f8d29..0039b37 100644 --- a/app/validate/CouponRelease.php +++ b/app/validate/CouponRelease.php @@ -15,7 +15,7 @@ class CouponRelease extends Validate 'type|优惠券类型' => 'require', 'start_time|开始时间' => 'require|date', 'end_time|结束时间' => 'require|date|checkEndTime', - 'name|优惠券名称' => 'require|length:3,32', + 'name|优惠券名称' => 'require|graph|length:3,32', 'money|金额' => 'require|>:0|<=:5000', 'deduction_money|扣除金额' => 'require|>=:0.1|<=:5000', 'image_url|预览图' => 'require', diff --git a/view/manager/agency/edit_channel.html b/view/manager/agency/edit_channel.html index 18c1e48..16a02ef 100644 --- a/view/manager/agency/edit_channel.html +++ b/view/manager/agency/edit_channel.html @@ -44,7 +44,7 @@