123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?php
- namespace app\common\model;
- use app\common\library\Redis;
- use think\Model;
- class SpecialRechargeUrl extends Model
- {
- // 表名
- protected $table = 'special_recharge_url';
-
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
-
- // 追加属性
- protected $append = [
- 'order_status_text',
- 'status_text'
- ];
-
-
- public function getOrderStatusList()
- {
- return ['0' => __('Order_status 0'),'1' => __('Order_status 1')];
- }
- public function getStatusList()
- {
- return ['normal' => __('Status normal'),'hidden' => __('Status hidden')];
- }
- public function getOrderStatusTextAttr($value, $data)
- {
- $value = $value ? $value : $data['order_status'];
- $list = $this->getOrderStatusList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getStatusTextAttr($value, $data)
- {
- $value = $value ? $value : $data['status'];
- $list = $this->getStatusList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- /**
- * 检测链接
- * @param $id
- * @return array|mixed
- * @throws \think\Exception
- * @throws \think\exception\DbException
- */
- public function checkUrl($id)
- {
- $result = [];
- //链接已支付 存一次redis
- $redisKey = 'RUL:'.$id;
- if (Redis::instance()->exists($redisKey)) {
- $result = json_decode(Redis::instance()->get($redisKey), true);
- return $result;
- }
- $row = $this->get($id);
- if (!$row) {
- return ['code' => 201, 'msg' => '记录不存在', 'data' => []];
- }
- $row = $row->toArray();
- if ($row['status'] == 'hidden') {
- $result = ['code' => 202, 'msg' => '链接已关闭', 'data' => $row];
- }
- if ($row['order_status'] == '1') {
- $result = ['code' => 203, 'msg' => '链接已支付', 'data' => $row];
- }
- if ($result) {
- Redis::instance()->set($redisKey, json_encode($result, 256),86400);
- return $result;
- }
- $code = 200;
- $msg = '';
- if ($row['out_trade_no'] && $row['order_status'] == '0') {
- $order = model("Orders")->where("out_trade_no", 'EQ', $row['out_trade_no'])->find();
- if ($order['state'] == '1') {
- $this->where('id', 'eq', $id)->update(['order_status' => '1']);
- $row['order_status'] = '1';
- $code = 203;
- $msg = '链接已支付';
- }
- }
- return ['code' => $code, 'msg' => $msg, 'data' => $row];
- }
- }
|