settter
parent
b5986ae653
commit
d143b55d3a
|
@ -5,16 +5,29 @@ use app\exception\RepositoryException;
|
|||
use app\model\BusinessCircle;
|
||||
use app\model\Category;
|
||||
use app\repository\AccountRepository;
|
||||
use app\repository\BillRepository;
|
||||
use app\repository\BusinessRepository;
|
||||
use app\repository\CouponRepository;
|
||||
use app\repository\DictionaryRepository;
|
||||
use app\repository\RechargeRepository;
|
||||
use app\service\wx\WechatPay;
|
||||
use app\validate\BusinessValidate;
|
||||
use Endroid\QrCode\Builder\Builder;
|
||||
use Endroid\QrCode\Encoding\Encoding;
|
||||
use Endroid\QrCode\ErrorCorrectionLevel\ErrorCorrectionLevelHigh;
|
||||
use Endroid\QrCode\RoundBlockSizeMode\RoundBlockSizeModeMargin;
|
||||
use Endroid\QrCode\Writer\PngWriter;
|
||||
use think\Collection;
|
||||
use think\Exception;
|
||||
use think\facade\Db;
|
||||
use think\exception\ValidateException;
|
||||
use app\model\{Account, ApplyStaff, Business as BusinessModel, Account as AccountModel, CouponMain};
|
||||
use app\model\{Account,
|
||||
Account as AccountModel,
|
||||
Activity as ActivityModel,
|
||||
ApplyStaff,
|
||||
Business as BusinessModel,
|
||||
CouponBill,
|
||||
CouponMain};
|
||||
use think\response\Json;
|
||||
use function EasyWeChat\Kernel\Support\generate_sign;
|
||||
|
||||
|
@ -192,6 +205,51 @@ class Business extends Base
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* 申请失败后
|
||||
* */
|
||||
public function revokeJoinStaffAuth()
|
||||
{
|
||||
$accountId = $this->request->user['user_id'] ?? 0;
|
||||
$account = AccountRepository::getInstance()->findById($accountId, [], function ($q) {
|
||||
return $q->with(['business'=>function($q){
|
||||
$q->lock(true);
|
||||
}, 'parent']);
|
||||
});
|
||||
if(empty($account)){
|
||||
return $this->json(6001,"登录失效");
|
||||
}
|
||||
if ($account->type != AccountModel::type_consumer) {
|
||||
return $this->json(4001, "用户状态错误");
|
||||
}
|
||||
|
||||
//检查有没有加入一个商家的申请
|
||||
$applyStaff = BusinessRepository::getInstance()->getApplyStaffByUserCode($account->user_code);
|
||||
if(empty($applyStaff)){
|
||||
return $this->json(4001, "申请记录不存在");
|
||||
}
|
||||
|
||||
if ($applyStaff->status == ApplyStaff::status_success) {
|
||||
return $this->json(4001, "该申请已通过");
|
||||
}
|
||||
|
||||
|
||||
// 待审核或者审核驳回 可以撤销 开始撤销操作
|
||||
Db::startTrans();
|
||||
try {
|
||||
$applyStaff->delete();
|
||||
Db::commit();
|
||||
return $this->json();
|
||||
}catch (RepositoryException $e){
|
||||
Db::rollback();
|
||||
return $this->json(5001, "撤销失败");
|
||||
}catch (Exception $e){
|
||||
Db::rollback();
|
||||
return $this->json(5002, "撤销失败");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前账号所属商家的信息
|
||||
* 适用范围:商户账号 或 商户员工账号
|
||||
|
@ -350,20 +408,36 @@ class Business extends Base
|
|||
return $this->json(6001,"登录失效",["showSubmitBtn"=>$showSubmitBtn]);
|
||||
}
|
||||
|
||||
//如果有商家 并且审核失败或者
|
||||
//如果有商家 并且审核失败或者待审核
|
||||
if (isset($account->business) && !empty($account->business) && in_array($account->business->state, [BusinessModel::state_off, BusinessModel::state_reviewing,])) {
|
||||
if ($account->business->state == BusinessModel::state_off) {
|
||||
return $this->json(4001, "认证被退回,请重新填写资料:" . $account->business->reason, ["business" => $account->business, "showSubmitBtn" => $showSubmitBtn]);
|
||||
return $this->json(4001, "认证被退回,请重新填写资料:" . $account->business->reason,
|
||||
["business" => $account->business, "showSubmitBtn" => $showSubmitBtn]);
|
||||
}
|
||||
$showSubmitBtn = false;
|
||||
return $this->json(4001, " 正在认证中请耐心等待", ["business" => $account->business, "showSubmitBtn" => $showSubmitBtn]);
|
||||
}
|
||||
|
||||
if($account->type == AccountModel::type_staff){
|
||||
$showSubmitBtn = false;
|
||||
return $this->json(4001, "您已经是员工,无需认证", ["showSubmitBtn" => $showSubmitBtn]);
|
||||
}
|
||||
|
||||
//检查有没有加入一个商家的申请
|
||||
$applyStaff = BusinessRepository::getInstance()->getApplyStaffByUserCode($account->user_code);
|
||||
if(!empty($applyStaff)){
|
||||
$showSubmitBtn = false;
|
||||
return $this->json(4001, "您有申请加入一个商家,不能认证", [ "showSubmitBtn" => $showSubmitBtn]);
|
||||
if($applyStaff->status == ApplyStaff::status_default){
|
||||
return $this->json(4001, "您有申请加入一个商家待审核,不能认证", [ "showSubmitBtn" => $showSubmitBtn ,"applyStaff"=>$applyStaff]);
|
||||
}
|
||||
if($applyStaff->status == ApplyStaff::status_fail){
|
||||
$showSubmitBtn = true;
|
||||
return $this->json(4001, "您申请加入商家,商家驳回了,请先撤销申请", [ "showSubmitBtn" => $showSubmitBtn ,"applyStaff"=>$applyStaff]);
|
||||
}
|
||||
if($applyStaff->status == ApplyStaff::status_success){
|
||||
return $this->json(4001, "您申请加入商家已通过,请不要重复认证", [ "showSubmitBtn" => $showSubmitBtn ,"applyStaff"=>$applyStaff]);
|
||||
}
|
||||
return $this->json(4001, "状态错误", [ "showSubmitBtn" => $showSubmitBtn ,"applyStaff"=>$applyStaff]);
|
||||
}
|
||||
|
||||
return $this->json(0,"success",[ "showSubmitBtn" => $showSubmitBtn]);
|
||||
|
@ -528,6 +602,7 @@ class Business extends Base
|
|||
throw new RepositoryException('您已经有申请加入一个商家,不能重复申请');
|
||||
}
|
||||
|
||||
//是否有认证商家的申请
|
||||
if(isset($account->business)&&$account->business){
|
||||
if($account->business->state==businessModel::state_on){
|
||||
throw new RepositoryException('您已经是商家');
|
||||
|
@ -535,7 +610,7 @@ class Business extends Base
|
|||
if($account->business->state==businessModel::state_reviewing){
|
||||
throw new RepositoryException('您有审核中商家认证申请');
|
||||
}
|
||||
throw new RepositoryException('您有被驳回商家认证申请');
|
||||
throw new RepositoryException('您有被驳回商家认证申请,请先撤销申请');
|
||||
}
|
||||
|
||||
//验证通过 写入申请
|
||||
|
@ -714,6 +789,73 @@ class Business extends Base
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 商家查看
|
||||
* */
|
||||
public function businessBill()
|
||||
{
|
||||
$page = $this->request->param('page/d', 1);
|
||||
$size = $this->request->param('size/d', 10);
|
||||
$startTime = $this->request->param('startTime/s');
|
||||
$endTime = $this->request->param('endTime/s');
|
||||
|
||||
$accountId = $this->request->user['user_id'] ?? 0;
|
||||
$accountRepo = AccountRepository::getInstance();
|
||||
|
||||
$account = $accountRepo->findById($accountId, [], function ($q) {
|
||||
return $q->with(["business"]);
|
||||
});
|
||||
|
||||
if (!isset($account->business) || empty($account->business)) {
|
||||
return $this->json(4001, "商家信息无效");
|
||||
}
|
||||
$businessCode = $account->business->code;
|
||||
$orders = ['id' => 'desc'];
|
||||
$list = BillRepository::getInstance()->apiBillList($page, $size, $businessCode, $startTime, $endTime, $orders);
|
||||
$bill_money_sum = BillRepository::getInstance()->getBillMoneySum($businessCode, $startTime, $endTime );
|
||||
|
||||
return $this->json(0,"success",["list"=>$list,"bill_money_sum"=>$bill_money_sum]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载商家核销二维码
|
||||
* */
|
||||
|
||||
public function downloadWriteOffCode()
|
||||
{
|
||||
$accountId = $this->request->user['user_id'] ?? 0;
|
||||
$accountRepo = AccountRepository::getInstance();
|
||||
|
||||
$account = $accountRepo->findById($accountId, [], function ($q) {
|
||||
return $q->with(["business"]);
|
||||
});
|
||||
|
||||
if (!isset($account->business) || empty($account->business)) {
|
||||
return $this->json(4001, "商家信息无效");
|
||||
}
|
||||
$businessCode = $account->business->code;
|
||||
$w = 3000;//尺寸
|
||||
|
||||
$logoImg = app()->getRootPath().'public/static/images/icon-logo.jpg';
|
||||
|
||||
$result = Builder::create()
|
||||
->writer(new PngWriter())
|
||||
->writerOptions([])
|
||||
->data($businessCode)
|
||||
->encoding(new Encoding('UTF-8'))
|
||||
->errorCorrectionLevel(new ErrorCorrectionLevelHigh())
|
||||
->size($w)
|
||||
->margin(10)
|
||||
->roundBlockSizeMode(new RoundBlockSizeModeMargin())
|
||||
->logoPath($logoImg)
|
||||
->logoResizeToHeight(ceil($w/6))
|
||||
->logoResizeToWidth(ceil($w/6))
|
||||
->logoPunchoutBackground(true)
|
||||
->build();
|
||||
|
||||
return $result->getDataUri();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -225,6 +225,7 @@ class Coupon extends Base
|
|||
"deduction_money" => $data['deduction_money'] ?? '',
|
||||
"image_url" => $data['image_url'] ?? '',
|
||||
"intro" => $data['intro'] ?? '',
|
||||
"white_list" => $data['white_list'] ?? '',
|
||||
"status" => CouponMain::status_on,
|
||||
"on_shelf" => CouponMain::on_shelf_off,//默认下架 后天审核上架
|
||||
"commission_agency" => $distributionProportion['agency'],
|
||||
|
@ -272,6 +273,81 @@ class Coupon extends Base
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改优惠券
|
||||
* */
|
||||
public function edit()
|
||||
{
|
||||
$accountId = $this->request->user['user_id'] ?? 0;
|
||||
$couponMainId = input("couponMainId/d");
|
||||
$account = AccountRepository::getInstance()->findById($accountId, [], function ($q) {
|
||||
return $q->with(['business'=>function($q){
|
||||
$q->lock(true);
|
||||
}, 'parent']);
|
||||
});
|
||||
if(empty($account)){
|
||||
return $this->json(6001,"登录失效");
|
||||
}
|
||||
if ($account->type == Account::type_consumer) {
|
||||
return $this->json(4001, "您不是商家");
|
||||
}
|
||||
|
||||
if (!isset($account->business) || empty($account->business)) {
|
||||
return $this->json(4001, "商家信息错误");
|
||||
}
|
||||
|
||||
$couponMain = CouponMain::findById($couponMainId,[],function ($q){
|
||||
return $q->with(["usingRule"]);
|
||||
});
|
||||
if (empty($couponMain)) {
|
||||
return $this->json(4001, "优惠券不存在");
|
||||
}
|
||||
if (!isset($couponMain->usingRule)||empty($couponMain->usingRule)) {
|
||||
return $this->json(4001, "优惠券信息错误");
|
||||
}
|
||||
$data = input();
|
||||
|
||||
//验证通过 不管是商家还是工作人员 都可以修改优惠券 只能修改指定字段
|
||||
$couponMainData = [
|
||||
"name" => $data['name'] ?? '',
|
||||
"type" => $data['type'] ?? 0,
|
||||
"type_name" => $data['type_name'] ?? '',
|
||||
"start_time" => $data['start_time'] ?? '',
|
||||
"end_time" => $data['end_time'] ?? '',
|
||||
"image_url" => $data['image_url'] ?? '',
|
||||
"intro" => $data['intro'] ?? '',
|
||||
"white_list" => $data['white_list'] ?? '',
|
||||
];
|
||||
|
||||
$usingRule = input("using_rule/a");
|
||||
|
||||
$validate = new CouponRelease();
|
||||
if (!$validate->scene("api_edit")->check($couponMainData)) {
|
||||
return $this->json(4001, $validate->getError());
|
||||
}
|
||||
|
||||
$usingRuleValidate = new CouponUsingRule();
|
||||
if (!$usingRuleValidate->check($usingRule)) {
|
||||
return $this->json(4001, $usingRuleValidate->getError());
|
||||
}
|
||||
|
||||
|
||||
//验证通过
|
||||
Db::startTrans();
|
||||
try {
|
||||
$couponMain->save($couponMainData);
|
||||
$couponMain->usingRule->save($usingRule);
|
||||
Db::commit();
|
||||
return $this->json();
|
||||
} catch (RepositoryException $e) {
|
||||
Db::rollback();
|
||||
return $this->json(5001, "修改失败失败" );
|
||||
} catch (\think\Exception $e) {
|
||||
Db::rollback();
|
||||
return $this->json(5002, "修改失败500" );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 商家管理优惠券
|
||||
* */
|
||||
|
@ -407,4 +483,20 @@ class Coupon extends Base
|
|||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取优惠券详情
|
||||
* */
|
||||
public function getCouponMainInfo()
|
||||
{
|
||||
$couponMainId = input("couponMainId/d");
|
||||
$couponMain = CouponMain::findById($couponMainId,[],function ($q){
|
||||
return $q->with("usingRule");
|
||||
});
|
||||
if(empty($couponMain)){
|
||||
return $this->json(4001,"优惠券不存在");
|
||||
}
|
||||
|
||||
return $this->json(0,"success",$couponMain->toArray());
|
||||
}
|
||||
}
|
|
@ -25,7 +25,7 @@ class Bill extends Base
|
|||
$page = $this->request->param('page/d', 1);
|
||||
$size = $this->request->param('size/d', 30);
|
||||
$orders = ['a.id' => 'desc'];
|
||||
$list = $repo->billList($page, $size, $keyword, $startTime, $endTime, $orders);
|
||||
$list = $repo->billList($page, $size, $keyword,null, $startTime, $endTime, $orders);
|
||||
$list['agency_money_sum'] = BillRepository::getInstance()->getAgencyMoneySum(CouponBill::agency_money, $keyword, $startTime, $endTime);
|
||||
$list['admin_money_sum'] = BillRepository::getInstance()->getAgencyMoneySum(CouponBill::admin_money, $keyword, $startTime, $endTime);
|
||||
$list['consumer_money_sum'] = BillRepository::getInstance()->getAgencyMoneySum(CouponBill::consumer_money, $keyword, $startTime, $endTime);
|
||||
|
|
|
@ -25,12 +25,13 @@ class BillRepository extends Repository
|
|||
* @param $page
|
||||
* @param $size
|
||||
* @param $keyword
|
||||
* @param null $businessCode
|
||||
* @param null $startTime
|
||||
* @param null $endTime
|
||||
* @param array $orders
|
||||
* @return array
|
||||
*/
|
||||
public function billList($page, $size, $keyword = null, $startTime = null, $endTime = null, $orders = ["id" => "desc"])
|
||||
public function billList($page, $size, $keyword = null, $businessCode = null,$startTime = null, $endTime = null, $orders = ["a.id" => "desc"])
|
||||
{
|
||||
$failData = [
|
||||
'total' => 0,
|
||||
|
@ -45,6 +46,9 @@ class BillRepository extends Repository
|
|||
->when(!empty($keyword), function ($q) use ($keyword) {
|
||||
$q->where("b.business_name|c.nick_name|d.name", "like", "%$keyword%");
|
||||
})
|
||||
->when(!empty($businessCode), function ($q) use ($businessCode) {
|
||||
$q->where("b.code", "=", $businessCode);
|
||||
})
|
||||
->when(MemberModel::is_agency(session("auth")['roles']), function ($q) {
|
||||
$q->where("b.agency_code", "=", session("auth")['business_code']);
|
||||
})
|
||||
|
@ -64,6 +68,38 @@ class BillRepository extends Repository
|
|||
return $failData;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* api获取签到流水列表
|
||||
* @param $page
|
||||
* @param $size
|
||||
* @param $keyword
|
||||
* @param null $businessCode
|
||||
* @param null $startTime
|
||||
* @param null $endTime
|
||||
* @param array $orders
|
||||
* @return array
|
||||
*/
|
||||
public function apiBillList($page, $size, $businessCode = null,$startTime = null, $endTime = null, $orders = ["id" => "desc"])
|
||||
{
|
||||
|
||||
return CouponBill::with(["couponMain","account"])
|
||||
->when(!empty($businessCode), function ($q) use ($businessCode) {
|
||||
$q->where("business_code", "=", $businessCode);
|
||||
})
|
||||
->when(!empty($startTime), function ($q) use ($startTime) {
|
||||
$q->whereTime("create_time", ">=", $startTime);
|
||||
})
|
||||
->when(!empty($endTime), function ($q) use ($endTime) {
|
||||
$q->whereTime("create_time", "<=", $endTime);
|
||||
})
|
||||
->page($page,$size)
|
||||
->order($orders)
|
||||
->select();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 充值流水列表
|
||||
* @param $page
|
||||
|
@ -209,6 +245,28 @@ class BillRepository extends Repository
|
|||
->sum("a." . $field);
|
||||
}
|
||||
|
||||
/**
|
||||
* 总流水
|
||||
* @param $businessCode
|
||||
* @param null $startTime
|
||||
* @param null $endTime
|
||||
* @return float
|
||||
*/
|
||||
public function getBillMoneySum($businessCode, $startTime=null, $endTime=null )
|
||||
{
|
||||
return CouponBill::alias("a")
|
||||
->join("account c", "a.user_code = c.user_code")
|
||||
->join("coupon_main b", "a.coupon_main_id = b.id")
|
||||
->where("a.business_code",$businessCode)
|
||||
->when(!empty($startTime), function ($q) use ($startTime) {
|
||||
$q->whereTime("a.create_time", ">=", $startTime);
|
||||
})
|
||||
->when(!empty($endTime), function ($q) use ($endTime) {
|
||||
$q->whereTime("a.create_time", "<=", $endTime);
|
||||
})
|
||||
->sum("b.deduction_money");
|
||||
}
|
||||
|
||||
/**
|
||||
* 总充值流水
|
||||
* @param null $keyword
|
||||
|
|
|
@ -26,11 +26,13 @@ class CouponRelease extends Validate
|
|||
'status|状态' => 'require|in:1,0',
|
||||
'on_shelf|上架状态' => 'require|in:1,0',
|
||||
//'intro|详情' => '',
|
||||
//'white_list|白名单' => '',
|
||||
];
|
||||
|
||||
|
||||
protected $scene = [
|
||||
'edit' => ['start_time', 'end_time', 'name',"status","on_shelf"],
|
||||
'api_edit' => ['name', 'type', 'start_time',"end_time","image_url"],
|
||||
];
|
||||
|
||||
protected function checkEndTime($value, $rule, $data = [])
|
||||
|
|
Loading…
Reference in New Issue