作者 刘朕
1 个管道 的构建 通过 耗费 1 秒

合并分支 'liuzhen' 到 'master'

Liuzhen



查看合并请求 !34
<?php
namespace app\admin\model;
use app\api\model\Base;
class UserWithdraw extends Base
{
}
\ No newline at end of file
... ...
... ... @@ -51,12 +51,12 @@ class Sms extends Api
$this->error(__('未注册'));
}
}
if (!Hook::get('sms_send')) {
$this->error(__('请在后台插件管理安装短信验证插件'));
}
// if (!Hook::get('sms_send')) {
// $this->error(__('请在后台插件管理安装短信验证插件'));
// }
$ret = Smslib::send($mobile, null, $event);
if ($ret) {
$this->success(__('发送成功'));
$this->success(__('发送成功'),['code'=>$ret]);
} else {
$this->error(__('发送失败,请检查短信配置是否正确'));
}
... ... @@ -96,7 +96,7 @@ class Sms extends Api
if ($ret) {
$this->success(__('成功'));
} else {
$this->error(__('验证码不正确'));
$this->error(__('验证码不正确'),$ret);
}
}
}
... ...
... ... @@ -3,19 +3,17 @@
namespace app\api\controller;
use addons\litestore\model\Litestoreorder;
use addons\wechat\library\Config as ConfigService;
use app\admin\model\UserWithdraw;
use app\api\model\Deposit;
use app\api\model\DepositOrder;
use app\api\model\Industry;
use app\api\model\LitestoreBanner;
use app\api\model\LitestoreGoodsSpec;
use app\api\model\Report;
use app\api\model\StoreApply;
use app\api\model\StoreComment;
use app\api\model\StoreInform;
use app\api\model\StoreOrder;
use app\api\model\UserSearch;
use app\api\model\UserScoreLog;
use app\api\validate\StoreValidate;
use app\common\controller\Api;
use EasyWeChat\Foundation\Application;
... ... @@ -177,7 +175,7 @@ class Store extends Api
'out_trade_no' => $order_sn,
'total_fee' => 1, // $param['money'] * 100
'spbill_create_ip' => request()->ip(), // 可选,如不传该参数,SDK 将会自动获取相应 IP 地址
'notify_url' => url('index/ajax/notify',[],true,true), // 支付结果通知网址,如果不设置则会使用配置里的默认地址
'notify_url' => url('index/ajax/store_notify',[],true,true), // 支付结果通知网址,如果不设置则会使用配置里的默认地址
'openid' => Db::name('third')->where('user_id',$this->auth->id)->value('openid'),
];
$order = new Order($attributes);
... ... @@ -411,16 +409,39 @@ class Store extends Api
}
$store = $this->get_store();
if($param['type'] == 1) {
$param['score'] = bcadd(config('site.send_score'),$param['red_package'],2);
$param['single'] = $param['red_package'] / $param['number'];
$param['score'] = bcadd(config('site.send_score'),$param['red_package'] * config('site.withdraw_percent'),2);
if($this->auth->score < $param['score']) {
$this->error('板币不足,请充值');
}
}
Db::startTrans();
$result = false;
$res_user = $res_log = true;
try{
$param['user_id'] = $this->auth->id;
$param['house_ids'] = ','.$param['house_ids'].',';
$model = new StoreInform();
$result = $model->add($param);
Db::commit();
if($param['type'] == 1) {
// 减少用户板币余额
$res_user = Db::name('user')->where('id',$param['user_id'])->setDec('score',$param['score']);
//记录钱包log
$insert_data = array(
'user_id' => $param['user_id'],
'score' => $param['score'],
'before' => $this->auth->score,
'after' => $this->auth->score - $param['score'],
'createtime' => time(),
'memo' => '发布信息',
);
$res_log = Db::name('user_score_log')->insert($insert_data);
}
if(!$result || !$res_user || !$res_log) {
Db::rollback();
} else {
Db::commit();
}
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
... ... @@ -428,7 +449,7 @@ class Store extends Api
Db::rollback();
$this->error($e->getMessage());
}
if(!$result) {
if(!$result || !$res_user || !$res_log) {
$this->error('提交失败');
}
$this->success('提交成功');
... ... @@ -751,6 +772,174 @@ class Store extends Api
}
/**
* 收支明细
* @ApiWeigh (10)
*
* @ApiTitle (收支明细)
* @ApiSummary (收支明细)
* @ApiMethod (POST)
* @ApiRoute (/api/store/score_log)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="page", type="integer", required=true, description="页数")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": {
"list": [
{
"id": 1,
"name": "行业名称",
"weigh": 0,
}
]
}
})
*/
public function score_log()
{
if($this->request->isPost()){
$param = (new StoreValidate())->goCheck('common');
$store = $this->get_store();
$page = $param['page'];
$where = [
'where' => ['store_id'=>$store['id']],
'with' => ['user_info']
];
$order = ['createtime'=>'DESC'];
$model = new UserScoreLog();
$score = $model->pageSelect($page,$where,'*',$order,config('option.num'));
$list = $score->items();
$return = [
'list' => $list,
'this_page' => $score->currentPage(),
'total_page' => $score->lastPage()
];
$this->success('请求成功',$return);
}
}
/**
* 提现
* @ApiWeigh (15)
*
* @ApiTitle (提现)
* @ApiSummary (提现)
* @ApiMethod (POST)
* @ApiRoute (/api/store/withdraw)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="money", type="integer", required=true, description="提现金额")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": {
})
*/
public function withdraw()
{
if($this->request->isPost()) {
$param = $this->request->param();
$validate = new \think\Validate([
'money' => 'require|number',
]);
$validate->message([
'money.require' => '请输入提现金额!',
'money.number' => '提现金额必须为数字!',
]);
if (!$validate->check($param)) {
$this->error($validate->getError());
}
$withdraw_percent = config('site.withdraw_percent');
$withdraw_percent = $withdraw_percent > 0 ? ($withdraw_percent / 100) : 1;
if ($param['money'] < 1) {
$this->error('提现金额不可小于1元');
}
if ($param['money'] > 5000) {
$this->error('提现金额不可大于5000元');
}
// 判断余额是否充足
if ($param['money'] / $withdraw_percent * 10 > $this->auth->money) {
$this->error('桃币余额不足,无法提现');
}
// 判断用户是否绑定微信
$user_openid = Db::name('third')->where(['user_id'=>$this->auth->id,'third_party'=>'wechat'])->value('openid');
if(!$user_openid) {
$this->error('请先绑定微信之后进行提现',40004);
}
// 提现记录
Db::startTrans();
$user_model = $this->auth->getUser();
$withdraw_model = new UserWithdraw();
$user = $user_model->where('id', $this->auth->id)->find();
$order_sn = date('YmdHis').rand(0000,9999);
$withdraw = [
'user_id' => $this->auth->id,
'before_money' => $this->auth->money,
'after_money' => $this->auth->money - $param['money'] / $withdraw_percent * 10,
'order_sn' => $order_sn,
'money' => $param['money'],
'percent' => $withdraw_percent
];
$result = $withdraw_model->isUpdate(false)->save($withdraw);
// 记录用户余额
$result_user = $user_model->isUpdate(true)->save(['money' => $user['money'] - $param['money'] / $withdraw_percent * 10], ['id' => $this->auth->id]);
if (!$result || !$result_user) {
Db::rollback();
$this->error('提现申请失败', [$result, $result_user]);
}
// // 微信提现
// $withdraw_percent = config('site.withdraw_percent');
// $options = get_addon_config('epay');
// $wechat_option = [
// 'app_id' => $options['wechat']['appid'],
// 'app_secret' => $options['wechat']['app_secret'],
// 'payment' => [
// 'merchant_id' => $options['wechat']['mch_id'],
// 'key' => $options['wechat']['key'],
// 'cert_path' => ROOT_PATH . 'addons' . $options['wechat']['cert_client'],
// 'key_path' => ROOT_PATH . 'addons' . $options['wechat']['cert_key'],
// ]
// ];
// $app = new Application($wechat_option);
// $merchantPay = $app->merchant_pay;
// $merchantPayData = [
// 'partner_trade_no' => $order_sn, //随机字符串作为订单号,跟红包和支付一个概念。
// 'openid' => $user_openid, //收款人的openid
// 'check_name' => 'NO_CHECK', //文档中有三种校验实名的方法 NO_CHECK OPTION_CHECK FORCE_CHECK
// 'amount' => $param['money'] * (100 - $withdraw_percent), //单位为分
// 'desc' => '用户提现',
// 'spbill_create_ip' => request()->ip(), //发起交易的IP地址
// ];
// $result = $merchantPay->send($merchantPayData);
// if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') {
// // 记录用户余额
// $result_user = $user_model->isUpdate(true)->save(['money' => $this->auth->money - $param['money']]);
// // 余额变动记录
// $log = [
// 'user_id' => $this->auth->id,
// 'money' => $param['money'],
// 'before' => $this->auth->money,
// 'after' => $this->auth->money - $param['money'],
// 'memo' => '用户微信提现'
// ];
// $result_log = Db::name('user_money_log')->insertGetId($log);
// if (!$result_user || !$result_log) {
// Db::rollback();
// $this->error('提现申请失败');
// }
// } else {
// Db::rollback();
// $this->error($result['err_code_des']);
// }
Db::commit();
$this->success('提现申请成功');
}
}
/**
* 获取店铺信息
* @param string $id 店铺id
*/
... ...
... ... @@ -14,7 +14,7 @@ class Sms
* 验证码有效时长
* @var int
*/
protected static $expire = 120;
protected static $expire = 600;
/**
* 最大允许检测的次数
... ... @@ -53,12 +53,12 @@ class Sms
$time = time();
$ip = request()->ip();
$sms = \app\common\model\Sms::create(['event' => $event, 'mobile' => $mobile, 'code' => $code, 'ip' => $ip, 'createtime' => $time]);
$result = Hook::listen('sms_send', $sms, null, true);
if (!$result) {
$sms->delete();
return false;
}
return true;
// $result = Hook::listen('sms_send', $sms, null, true);
// if (!$result) {
// $sms->delete();
// return false;
// }
return $code;
}
/**
... ... @@ -98,20 +98,23 @@ class Sms
if ($sms['createtime'] > $time && $sms['times'] <= self::$maxCheckNums) {
$correct = $code == $sms['code'];
if (!$correct) {
$sms->times = $sms->times + 1;
$sms->save();
// $sms->times = $sms->times + 1;
// $sms->delete();
return false;
} else {
$result = Hook::listen('sms_check', $sms, null, true);
// $result = Hook::listen('sms_check', $sms, null, true);
$sms->times = 1;
$result = $sms->save();
return $result;
}
} else {
// 过期则清空该手机验证码
self::flush($mobile, $event);
return false;
return 2;
}
} else {
return false;
return \app\common\model\Sms::where(['mobile' => $mobile, 'event' => $event])
->order('id', 'DESC')->buildSql();
}
}
... ...
... ... @@ -38,4 +38,5 @@ return array (
'contact' => '联系我们联系我们022-12345678',
'settled' => '上架入驻协议',
'send_score' => '800',
'withdraw_percent' => '100',
);
\ No newline at end of file
... ...
... ... @@ -18,7 +18,7 @@ use think\Lang;
class Ajax extends Frontend
{
protected $noNeedLogin = ['lang','callback_for_wxgzh','refund_notify'];
protected $noNeedLogin = ['lang','callback_for_wxgzh','store_notify','notify','refund_notify'];
protected $noNeedRight = ['*'];
protected $layout = '';
public function _initialize()
... ... @@ -49,6 +49,54 @@ class Ajax extends Frontend
}
/**
* 店铺申请回调
*/
public function store_notify()
{
$app = new Application(ConfigService::load());
$response = $app->payment->handleNotify(function($notify, $successful){
/*这里是支付回调逻辑处理,一下是DEMO*/
// 使用通知里的 "微信支付订单号" 或者 "商户订单号" 去自己的数据库找到订单
$out_trade_no=$notify->out_trade_no;
$info = Db::name('store')->where(['order_sn'=>$out_trade_no])->find();
if (!$info) { // 如果订单不存在
return 'Order not exist.'; // 告诉微信,我已经处理完了,订单没找到,别再通知我了
}
// 检查订单是否已经更新过支付状态
if ($info['transaction_id']) { // 假设订单字段“支付时间”不为空代表已经支付
return true; // 已经支付成功了就不再更新了
}
// 用户是否支付成功
if ($successful) {
Db::startTrans();
// 回填微信的订单号
$update['transaction_id'] = $notify->transaction_id;
$update['status'] = 2; //付款成功
$update['pay_time'] = time();
//更新状态: 已购买
$res_order = Db::name('store')->where(['id' => $info['id']])->update($update);
if(!$res_order) {
Db::rollback();
return false; // 返回处理完成
}
Db::commit();
} else {
// 用户支付失败
$update['transaction_id'] = $notify->transaction_id;
$update['status'] = 6; //异常-支付失败
Db::name('deposit_order')->where(['id' => $info['id']])->update($update);
return false; // 返回处理完成
}
return true; // 返回处理完成
});
$response->send();
}
/**
* 支付回调
*/
public function notify(){
... ...