| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- /**
- * 订单回调处理.
- * @author zhangjunbao <junbaoz1314@gmail.com>
- * @date 2020-01-29 10:13:09
- */
- declare(strict_types=1);
- namespace Modules\Api\Controllers;
- use App\Model\VipOrderModel;
- use App\Repositories\Service\PaymentService;
- use App\Repositories\Service\QueueService;
- use Carbon\Carbon;
- use Hyperf\Validation\Contract\ValidatorFactoryInterface;
- use Psr\SimpleCache\CacheInterface;
- class OrderController extends BaseController
- {
- /**
- * 订单回调处理
- * @param $type
- * @param $orderId
- * @param $gateway
- */
- public function notify($type, $orderId)
- {
- make(QueueService::class)->addPayNotifyJob(
- [
- 'method' => $this->request->getMethod(),
- 'order_id' => $orderId,
- 'order_type' => $type,
- 'order_gateway' => 1,
- 'data' => $this->request->all(),
- 'date' => Carbon::now()->toDateTimeString(),
- ]
- );
- $orderId = intval($orderId);
- $result = make(PaymentService::class)->notify($orderId, $type);
- return $result;
- }
- /**
- * 用户上传-支持成功凭证
- */
- public function proof(ValidatorFactoryInterface $validatorFactory)
- {
- $user_id = $this->getUserId();
- $inputData = $this->getJsonData();
- $rules = [
- 'order_sn' => 'required|string',
- 'file_path' => 'required|string', //客户端先请求"上传(视频/图片)"接口 拿到上传成功后的路径值,原样传过来
- ];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $order_sn = $inputData['order_sn'];
- $file_path = $inputData['file_path'];
- $where = ['order_sn'=>$order_sn];
- $select = '*';
- $r = VipOrderModel::query()
- ->selectRaw($select)
- ->where($where)
- ->first();
- if (!$r) {
- return json_fail('购买记录不存在');
- }
- if ($r['user_code'] != $user_id) {
- return json_fail('此记录不是你的,无权操作');
- }
- if ($r['payproof_imgs']) {
- return json_fail('你已上传凭证了,请勿重复操作');
- }
- $data = array(
- 'payproof_imgs' => $file_path,
- 'is_user_proof' => 1,
- );
- $re = VipOrderModel::query()
- ->where($where)
- ->update($data);
- if (!$re) {
- return json_fail('上传凭证失败');
- }
- return json_success('', '上传成功');
- }
- /**
- * 清除支付列表缓存
- *
- * @return string|void
- * @throws \Psr\SimpleCache\InvalidArgumentException
- */
- public function delPayListsCache()
- {
- $inputData = request()->all();
- if ($inputData['key'] != env('PAY_CENTER_KEY')) {
- return json_fail('nook');
- }
- make(CacheInterface::class)->delete('paymentType');
- return json_success('ok');
- }
- }
|