<?php

namespace app\api\controller;

use app\api\extend\Basic;
use app\model\Evaluate;
use app\model\HouseImgs;
use app\model\JournalAccounts;

/**
 * Created by PhpStorm.
 * User : zw
 * Date : 2017/12/12
 * Time : 17:24
 * Intro: 我的交易记录
 */
class TradeLog extends Basic
{

    protected $journalAccountsMode;
    protected $dbImg;
    protected $evaluateMode;

    public function __construct($request = null)
    {
        parent::__construct($request);
        $this->journalAccountsMode = new JournalAccounts();
        $this->dbImg = new HouseImgs();
        $this->evaluateMode = new Evaluate();
    }

    /**
     * 获取交易记录
     * @return \think\Response
     */
    public function getTradeList()
    {
        $params = $this->params;
        $param = array(
            "user_id" => "1",
            "phone" => "158****6165",
            "pageNo" => 1,
            "pageSize" => 15,
        );
        $pageNo = empty($params['pageNo']) ? 1 : $params['pageNo'];
        $pageSize = empty($params['pageSize']) ? 15 : $params['pageSize'];


        $order_ = 'a.created desc';

        $field = "a.id,a.tradecode,a.singntime,b.phpone,b.house_id";

        $result = $this->journalAccountsMode->getJournalAccountsList($pageNo, $pageSize, $order_, $field, $param);

        if (count($result) <= 0) {
            return $this->response("200", "请求数据为空");
        }
        foreach ($result as $key => $val) {
            $result[$key]["api_path"] = IMG_PATH;
            $imgParam["house_id"] = $val["house_id"];
            $imgParam["imgtype"] = 1; //默认主图
            $result[$key]["images"] = $this->dbImg->getHouseImages($imgParam, 1);
            $evaluateResult = $this->evaluateMode->getIsEvaluate(20, $val["house_id"], $param["user_id"]);
            $result["is_evaluate"] = count($evaluateResult) > 0 ? 1 : 0;

        }
        return $this->response("200", "request", $result);

    }

}