__('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]; } }