master
parent
4ced1bd6ea
commit
9d83d8397b
|
@ -3,6 +3,7 @@
|
|||
namespace app\controller\api;
|
||||
|
||||
use app\controller\BaseController;
|
||||
use think\facade\Config;
|
||||
use think\response\Json;
|
||||
|
||||
/**
|
||||
|
@ -22,6 +23,7 @@ class Base extends BaseController
|
|||
'jwt',
|
||||
'apiLogin' => ['except' => $this->noNeedLogin]
|
||||
];
|
||||
Config::load("extra/wechat","wechat");
|
||||
}
|
||||
|
||||
public function __call($method, $args)
|
||||
|
|
|
@ -4,15 +4,21 @@ namespace app\controller\api;
|
|||
use app\exception\RepositoryException;
|
||||
use app\model\BusinessCircle;
|
||||
use app\model\Category;
|
||||
use app\model\Recharge as RechargeModel;
|
||||
use app\repository\AccountRepository;
|
||||
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 think\Collection;
|
||||
use think\Exception;
|
||||
use think\facade\Db;
|
||||
use think\exception\ValidateException;
|
||||
use app\model\{Business as BusinessModel, Account as AccountModel, CouponMain};
|
||||
use app\model\{Account, Business as BusinessModel, Account as AccountModel, CouponMain};
|
||||
use think\response\Json;
|
||||
use function EasyWeChat\Kernel\Support\generate_sign;
|
||||
|
||||
/**
|
||||
* 商家端:商家
|
||||
|
@ -34,20 +40,21 @@ class Business extends Base
|
|||
public function registerBusiness()
|
||||
{
|
||||
$params = [
|
||||
'type'=> $this->request->param('type/d', 0),
|
||||
'business_license'=> $this->request->param('business_license', ''),
|
||||
'background'=> $this->request->param('background', ''),
|
||||
'business_name'=> $this->request->param('business_name', ''),
|
||||
'business_subtitle'=> $this->request->param('business_subtitle', ''),
|
||||
'business_license'=> $this->request->param('business_license', ''),
|
||||
'contact_name'=> $this->request->param('contact_name', ''),
|
||||
'contact_phone'=> $this->request->param('contact_phone', ''),
|
||||
'lat'=> $this->request->param('lat', ''),
|
||||
'lng'=> $this->request->param('lng', ''),
|
||||
'province'=> $this->request->param('province', ''),
|
||||
'city'=> $this->request->param('city', ''),
|
||||
'county'=> $this->request->param('county', ''),
|
||||
'business_address' => $this->request->param('business_address', ''),
|
||||
'lat'=> $this->request->param('lat', ''),
|
||||
'lng'=> $this->request->param('lng', ''),
|
||||
'business_circle_id' => $this->request->param('business_circle_id/d', 0),
|
||||
'agency_code' => $this->request->param('agency_code', ''),
|
||||
'type'=> $this->request->param('type/d', 0),
|
||||
'contact_name'=> $this->request->param('contact_name', ''),
|
||||
'contact_phone'=> $this->request->param('contact_phone', ''),
|
||||
];
|
||||
|
||||
$accountId = $this->request->user['user_id'] ?? 0;
|
||||
|
@ -63,6 +70,9 @@ class Business extends Base
|
|||
if (empty($account)) {
|
||||
throw new ValidateException('无效请求!');
|
||||
}
|
||||
if ($account->type !== Account::type_consumer) {
|
||||
throw new ValidateException('您已经是商家或者员工,不能认证');
|
||||
}
|
||||
|
||||
if (!$validate->scene('apiRegister')->check($params)) {
|
||||
throw new ValidateException($validate->getError());
|
||||
|
@ -88,6 +98,8 @@ class Business extends Base
|
|||
} elseif ($agencyBusiness['enable'] == self::BOOL_TRUE) {
|
||||
throw new ValidateException('该代理商已被封禁!');
|
||||
}
|
||||
|
||||
$params['is_assign'] = 1;
|
||||
}
|
||||
|
||||
$business = null;
|
||||
|
@ -99,6 +111,9 @@ class Business extends Base
|
|||
$params['is_delete'] = 0;
|
||||
$params['state'] = BusinessModel::state_reviewing;
|
||||
$params['enable'] = 0;
|
||||
$params['total_recharge'] = 0;
|
||||
$params['balance'] = 0;
|
||||
$params['is_agency'] = 0;
|
||||
$params['type_name'] = $businessCategory['name'];
|
||||
|
||||
if ($business) {
|
||||
|
@ -108,7 +123,7 @@ class Business extends Base
|
|||
|
||||
// 更新审批信息,重新审批
|
||||
$params['update_time'] = date('Y-m-d H:i:s');
|
||||
$business = $business->save($params);
|
||||
$business->save($params);
|
||||
|
||||
} else {
|
||||
// 添加审批记录
|
||||
|
@ -273,6 +288,103 @@ class Business extends Base
|
|||
return $this->json(0,"success",$data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 检查是有已经有商家审核了
|
||||
* */
|
||||
public function checkAuth()
|
||||
{
|
||||
$accountId = $this->request->user['user_id'] ?? 0;
|
||||
$account = AccountRepository::getInstance()->findById($accountId, [], function ($q) {
|
||||
return $q->with(['business', 'parent']);
|
||||
});
|
||||
if(empty($account)){
|
||||
return $this->json(6001,"登录失效");
|
||||
}
|
||||
|
||||
//如果有商家 并且审核失败或者
|
||||
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]);
|
||||
}
|
||||
return $this->json(4001, " 正在认证中请耐心等待",["business"=>$account->business]);
|
||||
}
|
||||
|
||||
//检查有没有加入一个商家的申请
|
||||
//TODO....
|
||||
|
||||
return $this->json();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 充值
|
||||
* */
|
||||
public function recharge()
|
||||
{
|
||||
$accountId = $this->request->user['user_id'] ?? 0;
|
||||
$money = input("money/f",1);
|
||||
$account = AccountRepository::getInstance()->findById($accountId, [], function ($q) {
|
||||
return $q->with(['business', 'parent']);
|
||||
});
|
||||
if(empty($account)||empty($account->business)){
|
||||
return $this->json(6001,"登录失效");
|
||||
}
|
||||
if ($money <= 0) {
|
||||
return $this->json(4001,"充值金额有误");
|
||||
}
|
||||
$money = floor($money*100)/100;
|
||||
Db::startTrans();
|
||||
try {
|
||||
|
||||
//创建充值订单
|
||||
if (!$order = RechargeRepository::getInstance()->createOrder($account->business_code, $account->open_id,$money)) {
|
||||
throw new RepositoryException('订单创建失败,请稍后重试');
|
||||
}
|
||||
//生成支付
|
||||
$time = time();
|
||||
$res = WechatPay::getInstance()->order->unify([
|
||||
'body' => '商家充值',
|
||||
'openid' => $account->open_id,
|
||||
'out_trade_no' => $order->order_num,
|
||||
'total_fee' => $money * 100,
|
||||
'trade_type' => 'JSAPI',
|
||||
'timeStamp' => $time,
|
||||
'product_id' => $order->id,
|
||||
'sign_type' => "MD5",
|
||||
'notify_url' => $this->request->domain() . "/api/recharge/notify.html",
|
||||
]);
|
||||
|
||||
if (!isset($res['prepay_id'])) {
|
||||
throw new RepositoryException('订单创建失败,请稍后重试');
|
||||
}
|
||||
$payData = [
|
||||
"appId" =>config("wechat.applets_appId"),
|
||||
"timeStamp" =>$time."",
|
||||
'nonceStr' => randomStr(0,16),
|
||||
'package' => 'prepay_id='.$res['prepay_id'],
|
||||
"signType" =>'MD5',
|
||||
];
|
||||
|
||||
$payData['sign'] = generate_sign($payData, config("wechat.key"));
|
||||
|
||||
Db::commit();
|
||||
return $this->json(0, "success", [
|
||||
"payData" => $payData
|
||||
]);
|
||||
|
||||
}catch (RepositoryException $e){
|
||||
Db::rollback();
|
||||
return $this->json(4001,"发起充值失败");
|
||||
}catch (Exception $e){
|
||||
echo $e->getMessage();
|
||||
Db::rollback();
|
||||
return $this->json(5001,"发起充值失败");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -162,6 +162,7 @@ class User extends Base
|
|||
'balance' => $account['business']['balance'],
|
||||
'enable' => $account['business']['enable'],
|
||||
],
|
||||
"alertMoney"=>config("wechat.balance")
|
||||
];
|
||||
|
||||
return $this->json(0, 'success', $businessRes);
|
||||
|
@ -174,6 +175,7 @@ class User extends Base
|
|||
'userType' => $account['type'],
|
||||
'userTypeDes' => Account::accountTypeDescList()[$account['type']] ?? '游客',
|
||||
'couponCount' => $couponCount,
|
||||
"alertMoney"=>config("wechat.balance")
|
||||
];
|
||||
|
||||
|
||||
|
|
|
@ -311,7 +311,11 @@ class Business extends Base
|
|||
Db::startTrans();
|
||||
try {
|
||||
$business->save(["state" => $state, "reason" => $reason]);
|
||||
//通过 就改变用户为商家
|
||||
if($state == BusinessModel::state_on){
|
||||
$account->save(["type" => Account::type_business]);
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return $this->json();
|
||||
} catch (RepositoryException $e) {
|
||||
|
|
|
@ -42,12 +42,14 @@ class RechargeRepository extends Repository
|
|||
/**
|
||||
* 创建一个支付订单
|
||||
* @param $businessCode
|
||||
* @param $openId
|
||||
* @param $money
|
||||
* @return Recharge|Model
|
||||
*/
|
||||
public function createOrder($businessCode, $money)
|
||||
public function createOrder($businessCode,$openId,$money)
|
||||
{
|
||||
$data = [
|
||||
"open_id" => $openId,
|
||||
"order_num" => createUuid(),
|
||||
"business_code" => $businessCode,
|
||||
"money" => $money,
|
||||
|
|
|
@ -16,9 +16,9 @@ class BusinessValidate extends Validate
|
|||
'lat' => 'require|between:-90,90',
|
||||
'lng' => 'require|between:-180,180',
|
||||
|
||||
'province|所属省份' => 'max:100',
|
||||
'city|所属城市' => 'max:100',
|
||||
'county|所属区县' => 'max:100',
|
||||
'province|所属省份' => 'require',
|
||||
'city|所属城市' => 'require',
|
||||
'county|所属区县' => 'require',
|
||||
'business_address|商家地址' => 'require|max:250',
|
||||
|
||||
'characteristic|商家特色' => 'max:250',
|
||||
|
|
Loading…
Reference in New Issue