1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?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,'操作成功'];
- }
- }
|