|
@@ -2,10 +2,10 @@
|
|
|
|
|
|
namespace App\Http\Controllers\Wap\Pay;
|
|
|
|
|
|
-use App\Client\Pay\BookOrderPaySuccess;
|
|
|
-use App\Client\Pay\ForeverOrderPaySuccess;
|
|
|
-use App\Client\Pay\RechargeOrderPaySuccess;
|
|
|
-use App\Client\Pay\YearOrderPaySuccess;
|
|
|
+use App\Modules\Trade\Pay\BookOrderPaySuccess;
|
|
|
+use App\Modules\Trade\Pay\ForeverOrderPaySuccess;
|
|
|
+use App\Modules\Trade\Pay\RechargeOrderPaySuccess;
|
|
|
+use App\Modules\Trade\Pay\YearOrderPaySuccess;
|
|
|
use App\Modules\Book\Services\BookGiftsService;
|
|
|
use App\Modules\Book\Services\ChapterService;
|
|
|
use App\Modules\OfficialAccount\Services\OfficialAccountService;
|
|
@@ -41,6 +41,7 @@ use App\Libs\Pay\Merchants\UnionPay;
|
|
|
use App\Modules\Activity\Services\ActivityService;
|
|
|
use App\Modules\SendOrder\Services\SendOrderService;
|
|
|
use App\Modules\Subscribe\Models\Order;
|
|
|
+use App\Modules\Trade\Models\PayMerchant;
|
|
|
use GuzzleHttp\Client;
|
|
|
|
|
|
class OrdersController extends Controller
|
|
@@ -1114,66 +1115,107 @@ class OrdersController extends Controller
|
|
|
*/
|
|
|
function wcback_union(Request $request)
|
|
|
{
|
|
|
- return UnionPay::notify($request, function ($order) {
|
|
|
- return $this->orderSuccess($order);
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 订单成功
|
|
|
- * @param Order $order
|
|
|
- */
|
|
|
- function orderSuccess(Order $order)
|
|
|
- {
|
|
|
-
|
|
|
- if (isset($order->status) && $order->status == 'PAID') {
|
|
|
- Log::info('has_pay:' . $order->trade_no);
|
|
|
- return true;
|
|
|
- }
|
|
|
- DB::beginTransaction();
|
|
|
- try {
|
|
|
-
|
|
|
- $uid = $order->uid;
|
|
|
- $distribution_channel_id = $order->distribution_channel_id;
|
|
|
- $product_id = $order->product_id;
|
|
|
- $product = ProductService::getProductSingle($product_id);
|
|
|
- switch ($product->type) {
|
|
|
- case 'YEAR_ORDER':
|
|
|
- $instance = new YearOrderPaySuccess($order);
|
|
|
- break;
|
|
|
- case 'BOOK_ORDER':
|
|
|
- $instance = new BookOrderPaySuccess($order);
|
|
|
- break;
|
|
|
- case 'TICKET_RECHARGE':
|
|
|
- $instance = new RechargeOrderPaySuccess($order);
|
|
|
- break;
|
|
|
- case 'FOREVER':
|
|
|
- $instance = new ForeverOrderPaySuccess($order);
|
|
|
- break;
|
|
|
+ $data = $request->all();
|
|
|
+ \Log::info('union_pay.notify: ');
|
|
|
+ \Log::info($data);
|
|
|
+ if (isset($data['merOrderId'])) {
|
|
|
+ $trade_no = $data['merOrderId'];
|
|
|
+ if ($trade_no) {
|
|
|
+ $order = OrderService::getByTradeNo($trade_no);
|
|
|
+ $transaction_id = $data['targetOrderId'];
|
|
|
+ if ($order) {
|
|
|
+ if (isset($order->status) && $order->status == 'PAID') {
|
|
|
+ Log::info('has_pay:' . $order->trade_no);
|
|
|
+ return 'SUCCESS';
|
|
|
+ }
|
|
|
+ $pay_merchant = DB::table('pay_merchants')->select('appid', 'source', 'config_info')
|
|
|
+ ->where('id', $order->pay_merchant_id)->where('is_enabled', 1)->first();
|
|
|
+ $instance = WechatPay::Union(json_decode($pay_merchant->config, true));
|
|
|
+ if ($instance->notify($data)) {
|
|
|
+ // 修改表比较多,开启事务
|
|
|
+ DB::beginTransaction();
|
|
|
+
|
|
|
+ $uid = $order->uid;
|
|
|
+ $distribution_channel_id = $order->distribution_channel_id;
|
|
|
+ $product_id = $order->product_id;
|
|
|
+ $product = ProductService::getProductSingle($product_id);
|
|
|
+ $send_order_id = $order->send_order_id;
|
|
|
+ $price = $product->price;
|
|
|
+ Log::info('save_order_end');
|
|
|
+
|
|
|
+ Log::info($product);
|
|
|
+
|
|
|
+ Log::info('product_type:' . $product->type);
|
|
|
+ $prize_fee = (int) (($product->price * 100) * 0.1);
|
|
|
+ $this->substituteOrderPrice($order->id, $prize_fee);
|
|
|
+ $this->smartPushTestBookPaidUv($order->from_bid, $order->uid, $order->price);
|
|
|
+ //获取用户充值次数
|
|
|
+ $order->pay_type = $this->getChargeTimes($order->uid);
|
|
|
+ // 更新其他定制Order表
|
|
|
+ if ($product->type == 'YEAR_ORDER') {
|
|
|
+ Log::info('YEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDERYEAR_ORDER');
|
|
|
+ $order_type = 'YEAR';
|
|
|
+ $this->yearOrder($uid, $distribution_channel_id, $price, $send_order_id);
|
|
|
+ $order->order_type = $order_type;
|
|
|
+ $order->status = 'PAID';
|
|
|
+ $order->pay_end_at = date('Y-m-d H:i:s');
|
|
|
+ $order->transaction_id = $transaction_id;
|
|
|
+ $order->save();
|
|
|
+ } elseif ($product->type == 'BOOK_ORDER') {
|
|
|
+ Log::info('BOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDERBOOK_ORDER');
|
|
|
+ $order_type = 'BOOK';
|
|
|
+ $this->bookOrder($product_id, $uid, $send_order_id, $price, $distribution_channel_id);
|
|
|
+ $order->order_type = $order_type;
|
|
|
+ $order->status = 'PAID';
|
|
|
+ $order->pay_end_at = date('Y-m-d H:i:s');
|
|
|
+ $order->transaction_id = $transaction_id;
|
|
|
+ $order->save();
|
|
|
+ } elseif ($product->type == 'TICKET_RECHARGE' || $product->type == 'NEW_USER') {
|
|
|
+ Log::info('TICKET_RECHARGETICKET_RECHARGETICKET_RECHARGETICKET_RECHARGETICKET_RECHARGE');
|
|
|
+ $order_type = 'RECHARGE';
|
|
|
+ $this->userCharge($product, $uid);
|
|
|
+ $order->order_type = $order_type;
|
|
|
+ $order->status = 'PAID';
|
|
|
+ $order->pay_end_at = date('Y-m-d H:i:s');
|
|
|
+ $order->transaction_id = $transaction_id;
|
|
|
+ $order->save();
|
|
|
+ } elseif ($product->type == 'FOREVER') {
|
|
|
+ Log::info('FOREVER------------------------FOREVER');
|
|
|
+ $order_type = 'FOREVER';
|
|
|
+ $this->foreverFreeOrder($uid, $distribution_channel_id, $price, $send_order_id);
|
|
|
+ $order->order_type = $order_type;
|
|
|
+ $order->status = 'PAID';
|
|
|
+ $order->pay_end_at = date('Y-m-d H:i:s');
|
|
|
+ $order->transaction_id = $transaction_id;
|
|
|
+ $order->save();
|
|
|
+ }
|
|
|
+ $this->successPayPushMsg($uid, $product, $order->id);
|
|
|
+ $this->orderStatistical($order);
|
|
|
+ DB::commit();
|
|
|
+ //redis 删除未支付的uid
|
|
|
+ try {
|
|
|
+ $key = 'leyuee:to_send_not_pay_uid:distribution_channel_id:' . $distribution_channel_id;
|
|
|
+ Redis::hdel($key, $uid);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Log::info('redis remote error-----------------------');
|
|
|
+ Log::info($e);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 注册动作-》回调订单
|
|
|
+ $action_type = 'CallBackOrder';
|
|
|
+ $param = [
|
|
|
+ 'order_sn' => isset($trade_no) ? $trade_no : '0',
|
|
|
+ 'openid' => isset($uid) ? $uid : '0', // 没有openid,用uid写log
|
|
|
+ ];
|
|
|
+ UserService::PushUserActionToQueue($action_type, $distribution_channel_id, $param);
|
|
|
+
|
|
|
+ $this->userProperty($uid, $price, $product->type, $order->activity_id);
|
|
|
+ //$this->huaweiActivity($order->activity_id,$uid,$product_id);
|
|
|
+ //交换订单时间
|
|
|
+ $this->exchangeUpdateAndCreated($order->id);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- $instance->success();
|
|
|
- $price = $product->price;
|
|
|
- $prize_fee = (int) (($product->price * 100) * 0.1);
|
|
|
- $this->substituteOrderPrice($order->id, $prize_fee);
|
|
|
- $this->smartPushTestBookPaidUv($order->from_bid, $order->uid, $order->price);
|
|
|
- $this->successPayPushMsg($uid, $product, $order->id);
|
|
|
- $this->orderStatistical($order);
|
|
|
- $key = 'leyuee:to_send_not_pay_uid:distribution_channel_id:' . $distribution_channel_id;
|
|
|
- Redis::hdel($key, $uid);
|
|
|
- // 注册动作-》回调订单
|
|
|
- $action_type = 'CallBackOrder';
|
|
|
- $param = [
|
|
|
- 'order_sn' => isset($order->trade_no) ? $order->trade_no : '0',
|
|
|
- 'openid' => isset($uid) ? $uid : '0', // 没有openid,用uid写log
|
|
|
- ];
|
|
|
- UserService::PushUserActionToQueue($action_type, $distribution_channel_id, $param);
|
|
|
- //用户属性
|
|
|
- $this->userProperty($uid, $price, $product->type, $order->activity_id);
|
|
|
- //交换订单时间
|
|
|
- $this->exchangeUpdateAndCreated($order->id);
|
|
|
- return true;
|
|
|
- } catch (\Exception $e) {
|
|
|
- return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -2009,7 +2051,7 @@ class OrdersController extends Controller
|
|
|
* @param $data
|
|
|
*
|
|
|
*/
|
|
|
- protected function createOrderTotal($data)
|
|
|
+ protected function createOrderTaotal($data)
|
|
|
{
|
|
|
$data['status'] = 'UNPAID';
|
|
|
$data['created_at'] = date('Y-m-d H:i:s');
|
|
@@ -2472,4 +2514,25 @@ class OrdersController extends Controller
|
|
|
} catch (\Exception $e) { }
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public function query()
|
|
|
+ {
|
|
|
+ $pay_merchant = PayMerchant::find(48);
|
|
|
+ $instance = WechatPay::Union($pay_merchant->source, json_decode($pay_merchant->config_info, true));
|
|
|
+ if ($instance->query('319420190918172727164500482012')) {
|
|
|
+ \Log::info('success');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public function refund()
|
|
|
+ {
|
|
|
+ $pay_merchant = PayMerchant::find(48);
|
|
|
+ $instance = WechatPay::Union($pay_merchant->source, json_decode($pay_merchant->config_info, true));
|
|
|
+ $data = [
|
|
|
+ 'trade_no' => '319420190918172727164500482012',
|
|
|
+ 'price' => 1
|
|
|
+ ];
|
|
|
+ if ($instance->refund($data)) {
|
|
|
+ \Log::info('success');
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|