Browse Source

Merge branch 'develop' of ssh://8.134.10.79:222/Leadfyy.co/hainan into develop

develop
lemon 4 years ago
parent
commit
4ca6bbde78
  1. 61
      app/Http/Controllers/Api/SharePayController.php
  2. 39
      app/Http/Controllers/Api/TestController.php
  3. 3
      app/Http/Controllers/Controller.php
  4. 3
      routes/api.php

61
app/Http/Controllers/Api/SharePayController.php

@ -0,0 +1,61 @@
<?php
namespace App\Http\Controllers\Api;
use App\Common\OrderStatus as Status;
use App\Http\Controllers\Controller;
use App\Models\Order;
use App\Models\User;
use EasyWeChat\Factory;
use EasyWeChat\Kernel\Exceptions\InvalidArgumentException;
use EasyWeChat\Kernel\Exceptions\InvalidConfigException;
use GuzzleHttp\Exception\GuzzleException;
/**
* 跳转支付
* Class SharePay
* @package App\Http\Controllers\Api
*/
class SharePayController extends Controller
{
public function pay()
{
$order_id = request()->input('id');
if (!$order_id) {
return $this->error('无效的ID');
}
//用户openid
$openid = User::query()->where('id', $this->user_id)->value('openid'); //此处要用where,value()用find有BUG
$order = Order::query()->whereIn('status', [Status::UNPAID, Status::PAY_EARNEST])->find($order_id);
$config = config('wechat.payment.default');
$config = array_merge($config, [
'app_id' => 'wxb35ef055a4dd8ad4',
'mch_id' => 'c782df1e6d3a03bb4a12e9d41c89cf9c',
'key' => 'lfyyhyz8888888888888888888888888',
]);
$app = Factory::payment($config);
try {
$result = $app->order->unify([
'body' => $order->title,
'out_trade_no' => $order->order_no . '-' . $order->status, //后面加status,主要是为了方便微信支付回调时区分定金(首付款)和尾款支付
'total_fee' => 1, //TODO 测试暂时注释 round($price * 100), //支付金额单位为分
'notify_url' => route('wxpay_notify', ['agent_id' => $this->agent_id]), // 支付结果通知网址,如果不设置则会使用配置里的默认地址
'trade_type' => 'JSAPI',
'openid' => $openid,
// 'profit_sharing' => 'Y', //Y分账,N不分账,默认不分账,Y大写
]);
} catch (InvalidArgumentException | InvalidConfigException | GuzzleException $e) {
return ['error' => $e->getMessage(), 'line' => $e->getLine()];
}
if (empty($result['prepay_id'])) {
return $result;
}
$jssdk = $app->jssdk;
$payConfig = $jssdk->bridgeConfig($result['prepay_id'], false) + ['id' => $order->id, 'order_no' => $order->order_no]; // 返回数组
return $this->success($payConfig);
}
}

39
app/Http/Controllers/Api/TestController.php

@ -31,4 +31,41 @@ class TestController
}
return '';
}
}
public function area()
{
$handle = fopen(Env::get('root_path').'2020-11行政区划(民政部).txt', 'r');
if ($handle) {
Db::execute('TRUNCATE `aqs_area`;');
while (($line = fgets($handle, 4096)) !== false) {
$line = trim($line);
$last2 = substr($line, 4, 2); //区划码后2位
$front2 = substr($line, 0, 2); //区划码前2位
$front4 = substr($line, 0, 4); //区划码前4位
//判断是否是直辖市,是直辖市则再插入一次上条记录作为二级联动
if( isset($last4, $arr, $parent_arr[$front2]) && $last4=='0000' && $last2!='00' ) {
$insert_id = Db::name('area')->insertGetId(['area_code'=>$arr[0], 'parent_id'=>$parent_arr[$front2], 'name'=>$arr[1]]);
$parent_arr[$front4] = $insert_id;
//对直辖市不做省直辖县处理,如:重庆市
$parent_arr[$front2] = $insert_id;
}
$last4 = substr($line, 2, 4); //区划码后4位
$arr = preg_split('/\s+/', $line);
if( $last4 == '0000' ) {
$insert_id = Db::name('area')->insertGetId(['area_code'=>$arr[0], 'parent_id'=>0, 'name'=>$arr[1]]);
$parent_arr[$front2] = $insert_id;
} else if( $last2 == '00' ) {
$insert_id = Db::name('area')->insertGetId(['area_code'=>$arr[0], 'parent_id'=>$parent_arr[$front2], 'name'=>$arr[1]]);
$parent_arr[$front4] = $insert_id;
} else {
//考虑到省直辖县级市情况,如:海南琼海市、湖北仙桃市等,但重庆市的省辖县除外(已在上面判断直辖市逻辑中做处理)
$parent_id = $parent_arr[$front4] ?? $parent_arr[$front2];
Db::name('area')->insertGetId(['area_code'=>$arr[0], 'parent_id'=>$parent_id, 'name'=>$arr[1]]);
}
}
}
}}

3
app/Http/Controllers/Controller.php

@ -26,6 +26,9 @@ class Controller extends BaseController
}
$this->agent_id = Cache::get($appid, 0);
if ($this->agent_id == 3) {
$this->agent_id = 1;
}
}
protected function success($data = [], $msg = 'success', $code = 0, $status = 200)

3
routes/api.php

@ -28,6 +28,9 @@ Route::namespace('App\Http\Controllers\Api')
Route::post('refund/{agent_id}', 'WxpayController@refund')->name('wxpay_refund'); //退款通知,aid为代理商ID
});
# 跳转支付
Route::post('share_pay', \App\Http\Controllers\Api\SharePayController::class . '@pay');
# 仅用于测试
Route::get('t/index', \App\Http\Controllers\Api\TestController::class . '@index');

Loading…
Cancel
Save