...
|
...
|
@@ -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
|
|
|
*/
|
...
|
...
|
|