quanwei
2025-12-12 b8961f178740f99ce54cfcbfd88235eaf8b79872
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
 
namespace app\api\model\plus\release;
 
use app\common\model\plus\release\DemandApply as ApplyModel;
 
 
/**
 * 申请模型
 */
class DemandApply extends ApplyModel
{
    /**
     * 隐藏字段
     * @var array
     */
    protected $hidden = [
        'create_time',
        'update_time',
    ];
 
    /**
     * 是否为申请中
     */
    public static function isApplying($user_id)
    {
        $detail = self::detail(['user_id' => $user_id]);
        return $detail ? ((int)$detail['apply_status']['value'] === 10) : false;
    }
 
    /**
     * 获取最新的一条申请数据
     */
    public function getDatail($user_id)
    {
        $detail = $this->where(['user_id' => $user_id])->order("create_time desc")->find();
        return $detail;
    }
 
    /**
     * 提交申请
     */
    public function submit($user, $data)
    {
        // 数据整理
        $data = [
            'user_id' => $user['user_id'],
            'real_name' => trim($data['name']),
            'mobile' => trim($data['mobile']),
            // 'province_id' => trim($data['province_id']),
            // 'city_id' => trim($data['city_id']),
            // 'region_id' => trim($data['region_id']),
            // 'location_address' => $data['location_address'],
            // 'longitude' => $data['longitude'],
            // 'latitude' => $data['latitude'],
            // 'detail' => $data['detail'],
            'apply_type' => 10,
            'apply_status' => 10,
            'apply_time' => time(),
            'app_id' => self::$app_id,
        ];
        return $this->add($user, $data);
    }
 
    /**
     * 更新申请信息
     */
    private function add($user, $data)
    {
        // 实例化模型
        $model = self::detail(['user_id' => $user['user_id']]) ?: $this;
        // 更新记录
        $this->startTrans();
        try {
            // 保存申请信息
            $model->save($data);
            $this->commit();
            return true;
        } catch (\Exception $e) {
            $this->error = $e->getMessage();
            $this->rollback();
            return false;
        }
    }
 
}