<?php

namespace Pay\Lib;

use Dever;

class Manage
{
    public function showOrderStatus($id)
    {
        $info = Dever::db('pay/order')->one($id);
        if ($info) {
            if ($info['status'] == 1) {
                #return '*已支付';
                return '待支付';
            } elseif ($info['status'] == 2) {
                return '已支付';
            } elseif ($info['status'] == 3) {
                return '支付失败';
            } elseif ($info['status'] == 5) {
                $table['状态'] = '已退款';
                $manage = Dever::db('manage/admin')->one($info['tk_admin']);
                $table['备注'] = $info['tk_desc'];
                $table['截图'] = '<a><img src="'.$info['tk_pic'].'" style="width:150px" /></a>';
                //$table['退款时间'] = date('Y-m-d H:i:s', $info['tk_time']);
                $table['操作人'] = $manage['username'];
                return Dever::table($table);
            }
        }
    }

    # 更新渠道的同时，更新passport下的项目
    public function updateChannel($id, $name, $param)
    {
        if (!Dever::project('passport')) {
            return;
        }
        $data['name'] = Dever::param('name', $param);
        # 获取小程序信息，同步过去
        $where['channel_id'] = $id;
        $where['system_source'] = 5;
        $account = Dever::db('pay/account')->one($where);
        if ($account) {
            $data['appid'] = $account['appid'];
            $data['secret'] = $account['appsecret'];
        }
        # 与passport下的id 对应
        $info = Dever::db('passport/system')->one($id);
        if (!$info) {
            Dever::db('passport/system')->insert($data);
        } else {
            $data['where_id'] = $info['id'];
            $data['state'] = Dever::param('state', $param);
            if (!$data['name']) {
                unset($data['name']);
            };
            Dever::db('passport/system')->update($data);
        }
        return $info;
    }
}