123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339 |
- <?php
- namespace app\api\controller;
- use addons\epay\library\Service;
- use app\admin\model\Fishery;
- use app\admin\model\FisherySuppliers;
- use app\admin\model\method\Time;
- use app\admin\model\Smslog;
- use app\admin\model\Smsorder;
- use app\admin\model\Tzmoneylog;
- use app\admin\model\Tzmoneyrecharge;
- use app\admin\model\UserMoneyLog;
- use app\admin\model\UserMoneyRecharge;
- use app\api\controller\shop\Order;
- use app\api\model\order\OrderItem;
- use app\common\controller\Api;
- use app\common\library\Log;
- use app\common\service\OrderCallback;
- use think\Db;
- use think\Exception;
- /**
- * @ApiInternal
- * Class 回调
- * @package app\api\controller
- */
- class Notify extends Api
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- //钓鱼订单支付回调
- public function method_notify(){
- $paytype = $this->request->param('type');
- file_put_contents("example.txt",$paytype);
- \think\Log::write('【钓鱼订单支付】回调,type:'.$paytype);
- $pay = Service::checkNotify($paytype);
- if (!$pay) {
- file_put_contents("exampl.txt",'出错了');
- \think\Log::write('【钓鱼订单支付】回调,签名错了');
- echo '签名错误';
- return;
- }
- $data = $pay->verify();
- file_put_contents("exampl.txt",json_encode($data));
- try {
- $out_trade_no = $data['out_trade_no'];
- \think\Log::write('【钓鱼订单支付】回调,out_trade_no:'.$out_trade_no);
- $order_model = new \app\admin\model\Order();
- $order_item_model = new \app\admin\model\Orderitem();
- $user_model = new \app\admin\model\User();
- $time_model = new Time();
- $score = new Pay();
- $number = $order_model->where('order_no',$out_trade_no)->field('item_money,wucan_money,user_id,id')->find();
- $time_number = $order_item_model->where('order_id',$number['id'])->where('type',1)->field('number,time_id')->find();
- $number_sta = $time_model->where('id',$time_number['time_id'])->value('sale_num');
- $user_number = $user_model->where('id',$number['user_id'])->value('score');
- $zong = ceil($number['item_money']+$user_number+$number['wucan_money']);
- $score->score($number['user_id'],$zong,'下单返利积分');
- Db::name('user')->where('id',$number['user_id'])->update(['score'=>$zong]);
- $order_model->isUpdate('true',['order_no'=>$out_trade_no])->save(['status'=>2,'pay_time'=>time()]);
- $time_model->isUpdate('true',['id'=>$time_number['time_id']])->save(['sale_num'=>$number_sta-$time_number['number']]);
- //你可以在此编写订单逻辑
- } catch (Exception $e) {
- }
- //下面这句必须要执行,且在此之前不能有任何输出
- return $pay->success()->send();
- }
- //短信购买订单支付回调
- public function sms_notify(){
- $paytype = $this->request->param('type');
- $pay = Service::checkNotify($paytype);
- if (!$pay) {
- echo '签名错误';
- return;
- }
- $data = $pay->verify();
- file_put_contents('w_pay.txt',json_encode($data));
- try {
- $out_trade_no = $data['out_trade_no'];
- $smslog_model= new Smsorder();
- $user_model = new \app\admin\model\User();
- $number = $smslog_model->where('order_no',$out_trade_no)->field('number,user_id')->find();
- $user_number = $user_model->where('id',$number['user_id'])->value('sms_number');
- $num = $number['number']+$user_number;
- $user_model->isUpdate('true',['id'=>$number['user_id']])->save(['sms_number'=>$num]);
- $smslog_model->isUpdate('true',['order_no'=>$out_trade_no])->save(['status'=>1]);
- //你可以在此编写订单逻辑
- } catch (Exception $e) {
- }
- //下面这句必须要执行,且在此之前不能有任何输出
- return $pay->success()->send();
- }
- public function release_notify(){
- $paytype = $this->request->param('type');
- $pay = Service::checkNotify($paytype);
- if (!$pay) {
- \think\Log::write('【发布鱼塘】回调签名错误,paytype:',$paytype);
- echo '签名错误';
- return;
- }
- $data = $pay->verify();
- try {
- $out_trade_no = $data['out_trade_no'];
- $yutang_model = new \app\admin\model\Yutang();
- $yutang_model->isUpdate('true',['order_no'=>$out_trade_no])->save(['status'=>2]);
- //你可以在此编写订单逻辑
- } catch (Exception $e) {
- }
- //下面这句必须要执行,且在此之前不能有任何输出
- return $pay->success()->send();
- }
- //充值订单支付回调
- public function balance_notify(){
- $paytype = $this->request->param('type');
- $pay = Service::checkNotify($paytype);
- if (!$pay) {
- echo '签名错误';
- return;
- }
- $data = $pay->verify();
- try {
- $out_trade_no = $data['out_trade_no'];
- $smslog_model= new Tzmoneyrecharge();
- $user_model = new \app\admin\model\User();
- $log_model = new Tzmoneylog();
- $number = $smslog_model->where('order_no',$out_trade_no)->field('money,user_id')->find();
- $add_data =[
- 'user_id'=>$number['user_id'],
- 'type'=>2,
- 'form'=>'余额充值',
- 'amount'=>$number['money'],
- 'create_time'=>time(),
- ];
- $user_number = $user_model->where('id',$number['user_id'])->field('t_money,t_cmoney')->find();
- $user_model->isUpdate('true',['id'=>$number['user_id']])->save(['t_money'=>$number['t_cmoney']+$user_number['t_cmoney'],'t_cmoney'=>$number['money']+$user_number['t_cmoney']]);
- $smslog_model->isUpdate('true',['order_no'=>$out_trade_no])->save(['status'=>2]);
- $log_model->insert($add_data);
- //你可以在此编写订单逻辑
- } catch (Exception $e) {
- }
- //下面这句必须要执行,且在此之前不能有任何输出
- return $pay->success()->send();
- }
- /**
- * 用户-钱包充值订单支付回调
- * 1、用户余额
- * 2、用户余额记录
- * 3、修改充值订单
- */
- public function user_recharge_notify(){
- $paytype = $this->request->param('type');
- $pay = Service::checkNotify($paytype);
- if (!$pay) {
- echo '签名错误';
- return;
- }
- $data = $pay->verify();
- try {
- $payamount = $paytype == 'alipay' ? $data['total_amount'] : $data['total_fee'] / 100;
- $out_trade_no = $data['out_trade_no'];
- //你可以在此编写订单逻辑
- // $payamount = 100 / 100;
- // $out_trade_no = 'CZ202302061655249720003';
- // $data = [];
- // 查询当前充值订单
- $recharge_model = new UserMoneyRecharge();
- $recharge_info = $recharge_model->where('order_sn',$out_trade_no)->find();
- if(!$recharge_info){
- \think\Log::write('支付回调错误【用户-钱包充值订单】未查询到用户充值订单,返回信息:'.json_encode($data));
- return ; // todo
- // return $pay->success()->send();
- }
- Db::startTrans();
- try {
- $user_id = $recharge_info->user_id;
- $user = \app\api\model\User::find($user_id);
- $money_log = [
- 'user_id' => $user_id,
- 'type' => 2,
- 'memo' => '余额充值',
- 'money' => $payamount,
- 'before' => $user->money,
- 'after' => $user->money + $payamount,
- 'createtime' => time(),
- ];
- $money_log_model = new UserMoneyLog();
- $money_log_model->insert($money_log);
- // 用户几个
- $user->money += $payamount;
- $user->save();
- $recharge_data = [
- 'pay_time' => time(),
- 'status' => 2
- ];
- $recharge_info->save($recharge_data);
- Db::commit();
- } catch (Exception $e) {
- \think\Log::write('支付回调错误【用户-钱包充值订单】错误信息:'.$e.'。保存错误,返回信息:'.json_encode($data));
- }
- } catch (Exception $e) {
- }
- //下面这句必须要执行,且在此之前不能有任何输出
- return $pay->success()->send();
- }
- /**
- * 塘主支付入驻资金 回调
- * 1、用户--改为已缴费
- * 2、入驻信息修改
- */
- public function fishery_notify(){
- $paytype = $this->request->param('type');
- \think\Log::write('【塘主支付入驻资金】回调 starting,paytype:'.$paytype);
- $pay = Service::checkNotify($paytype);
- if (!$pay) {
- echo '签名错误';
- \think\Log::write('【塘主支付入驻资金】回调签名错误,paytype:'.$paytype);
- return;
- }
- $data = $pay->verify();
- \think\Log::write('【塘主支付入驻资金】支付返回信息:'.json_encode($data));
- try {
- $payamount = $paytype == 'alipay' ? $data['total_amount'] : $data['total_fee'] / 100;
- $out_trade_no = $data['out_trade_no'];
- //你可以在此编写订单逻辑
- // $payamount = 0.01;
- // $out_trade_no = 'RZ202302161602024840016';
- // $data = [];
- // 查询申请入驻记录
- $fishery_model = new Fishery();
- $fishery_info = $fishery_model->where('pay_no',$out_trade_no)->where('status',5)->find();
- if(!$fishery_info){
- \think\Log::write('支付回调错误【塘主支付入驻资金】未查询到关联订单号,返回信息:'.json_encode($data));
- }else{
- Db::startTrans();
- try {
- $user_id = $fishery_info->user_id;
- $user = \app\api\model\User::find($user_id);
- // 用户--改为已缴费
- $user->is_pond = 5;
- $user->save();
- // 入驻信息修改
- $fishery_data = [
- 'pay_time' => time(),
- 'status' => 4
- ];
- $fishery_info->save($fishery_data);
- Db::commit();
- } catch (Exception $e) {
- Db::rollback();
- \think\Log::write('支付回调错误【塘主支付入驻资金】错误信息:'.$e.'。保存错误,返回信息:'.json_encode($data));
- }
- }
- } catch (Exception $e) {
- }
- \think\Log::write('【塘主支付入驻资金】回调 end');
- //下面这句必须要执行,且在此之前不能有任何输出
- return $pay->success()->send();
- }
- /**
- * 渔场主供货信息 回调
- * 1、修改供货信息支付状态 和 发布状态
- */
- public function suppliers_notify(){
- $paytype = $this->request->param('type');
- $pay = Service::checkNotify($paytype);
- if (!$pay) {
- echo '签名错误';
- return;
- }
- $data = $pay->verify();
- try {
- \think\Log::write('支付回调【渔场主供货信息】,返回信息:'.json_encode($data));
- $payamount = $paytype == 'alipay' ? $data['total_amount'] : $data['total_fee'] / 100;
- $out_trade_no = $data['out_trade_no'];
- //你可以在此编写订单逻辑
- // $payamount = 1000 / 100;
- // $out_trade_no = 'RZ202302071540128800003';
- // $data = [];
- $suppliers_model = new FisherySuppliers();
- $suppliers_info = $suppliers_model
- //->where('user_id', $this->auth->id)
- ->where('pay_no', $out_trade_no)
- ->where('status', 2)
- ->find();
- if(!$suppliers_info){
- \think\Log::write('支付回调错误【渔场主供货信息】未查询到关联订单号,返回信息:'.json_encode($data));
- return ; // todo
- // return $pay->success()->send();
- }
- // 回调处理
- OrderCallback::Suppliers($suppliers_info);
- } catch (Exception $e) {
- }
- //下面这句必须要执行,且在此之前不能有任何输出
- return $pay->success()->send();
- }
- }
|