<?php


namespace app\api\controller\custom;


use app\model\MarketCustomer;
use support\Request;

class MarketCustom
{
    public function updateStatus(Request $request)
    {
        $params = $request->post();
        if (empty($params['mobile'])) {
            return json_fail('手机号不能为空');
        }
        $mobile = $params['mobile'];
        $where = [
            ['mobile', '=', $mobile],
            [function($query) {
                $query->orWhere(function ($query){
                    $diffNums = (60 * 60 * 24 * 30);
                    $currentTime = time();
                    $query->whereRaw("((visit_time + {$diffNums}) - {$currentTime} > 0)")->where('current_status', '=', 1);
                })->orWhereIn('current_status', [2,3,4]);
            }],
            ['check_status', '=', 2]
        ];
        $info = MarketCustomer::where($where)->first();
        if (empty($info)) {
            return json_fail('客户不存在');
        }
        $info->current_status = 3;
        $result = $info->save();
        if ($result) {
            return json_success('修改成功');
        } else {
            return json_fail('修改失败');
        }
    }
}