123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- namespace app\common\model;
- use think\Db;
- use think\Model;
- /**
- * 支付订单
- */
- class PayOrderModel extends Model
- {
- // 表名
- protected $name = 'pay_order';
- // 开启自动写入时间戳字段
- protected $autoWriteTimestamp = false;
- // 定义时间戳字段名
- protected $createTime = false;
- protected $updateTime = false;
- protected $deleteTime = false;
- /**
- * 余额充值支付回调
- * @param $out_trade_no
- * @return array
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public static function recharge($out_trade_no)
- {
- Db::startTrans();
- if (!$order = self::where('out_trade_no',$out_trade_no)->lock(true)->find()) {
- Db::rollback();
- return [false,'未找到订单'];
- }
- if ($order['order_status'] != 0) {
- Db::rollback();
- return [true,'订单已支付'];
- }
- //更新订单状态
- if (!self::where(['out_trade_no' => $out_trade_no])->update(['order_status' => 1, 'notifytime' => time()])) {
- Db::rollback();
- return [false,'订单状态更新失败'];
- }
- //钱包更新
- $walletService = new Wallet();
- if (!$walletService->change($order['user_id'], $order['order_amount'], 'money', 10, '充值', 'pay_order', $order['table_id'])) {
- Db::rollback();
- return [false,'余额充值失败'];
- }
- Db::commit();
- return [true,'操作成功'];
- }
- /**
- * 老年大学活动支付回调
- * @param $out_trade_no
- * @return array
- */
- public static function university_event($out_trade_no)
- {
- Db::startTrans();
- if (!$info = self::where('out_trade_no',$out_trade_no)->lock(true)->find()){
- Db::rollback();
- return [false,'未找到订单'];
- }
- if ($info['order_status'] == 1){
- Db::rollback();
- return [true,'订单已支付'];
- }
- //更新订单状态
- if (!self::where(['id' => $info['id']])->update(['status' => 1])) {
- Db::rollback();
- return [false,'订单状态更新失败'];
- }
- if (!UniversityEventApplyModel::where('id',$info['table_id'])->update(['status' => 1,'pay_time' => time()])) {
- Db::rollback();
- return [false,'活动订单状态更新失败'];
- }
- Db::commit();
- return [true,'操作成功'];
- }
- /**
- * 老年大学活动支付回调
- * @param $out_trade_no
- * @return array
- */
- public static function vip($out_trade_no)
- {
- Db::startTrans();
- if (!$info = self::where('out_trade_no',$out_trade_no)->lock(true)->find()){
- Db::rollback();
- return [false,'未找到订单'];
- }
- if ($info['order_status'] == 1){
- Db::rollback();
- return [true,'订单已支付'];
- }
- //更新订单状态
- if (!self::where(['id' => $info['id']])->update(['status' => 1])) {
- Db::rollback();
- return [false,'订单状态更新失败'];
- }
- if (!VipOrderModel::where('id',$info['table_id'])->update(['status' => 1,'pay_time' => time()])) {
- Db::rollback();
- return [false,'VIP订单状态更新失败'];
- }
- if (!VipCouponUserModel::where('order_id',$info['table_id'])->update(['status' => 1,'update_time' => time()])) {
- Db::rollback();
- return [false,'VIP订单状态更新失败'];
- }
- Db::commit();
- return [true,'操作成功'];
- }
- }
|