Blame view

application/admin/model/fastflow/bill/Common.php 2.53 KB
2db47680   hexiaodong   chore: 初始提交 php 遗...
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
87
88
89
90
91
92
93
94
95
96
  <?php
  
  namespace app\admin\model\fastflow\bill;
  
  
  use app\admin\model\Admin;
  use think\Config;
  use think\Model;
  use fastflow\api;
  
  class Common extends Model
  {
  
      // 追加属性
      protected $append = [
          'initiator',
          'bill',
          'flow_auth',
          'runthread_info',
          'flow_progress',
          'flow_auth_text',
      ];
  
      public function __construct($data = [])
      {
          parent::__construct($data);
          if(isset($this->appendAttr))
          {
              $this->append = array_unique(array_merge($this->append,$this->appendAttr));
          }
      }
      // 定义全局的查询范围
      protected function base($query)
      {
          // $query->where($query->getTable().'.status','<>','-1');
      }
      public function getName()
      {
          return $this->name;
      }
  
      public function getInitiatorAttr($value, $data)
      {
          $createUserId = isset($data['initiator_id']) ? $data['initiator_id'] : 0;
          if ($createUserId === '' || $createUserId === null) {
              $createUserId = 0;
          }
          $user = Admin::find($createUserId);
          if ($user) {
              return $user['nickname'];
          }
          return '';
      }
  
      public function getBillAttr($value, $data)
      {
          return Config::get('database')['prefix'] . $this->name;
      }
  
      public function getFlowAuthAttr($value, $data)
      {
          $bill = Config::get('database')['prefix'] . $this->name;
          $initiatorId = isset($data['initiator_id']) ? $data['initiator_id'] : 0;
          $billId = isset($data['id']) ? $data['id'] : 0;
          $info = (new api())->getBillAuthInfo($initiatorId, $bill, $billId);
          return is_array($info) ? $info : ['code' => 0, 'msg' => ''];
      }
  
      public function getFlowAuthTextAttr($value, $data)
      {
          $auth = $this->getFlowAuthAttr($value, $data);
          return (is_array($auth) && isset($auth['msg'])) ? $auth['msg'] : '';
      }
  
      public function getRunthreadInfoAttr($value, $data)
      {
          $bill = Config::get('database')['prefix'] . $this->name;
          $billId = isset($data['id']) ? $data['id'] : 0;
          try {
              return (new api())->getRunThreadInfo($bill, $billId);
          } catch (\Throwable $e) {
              return [];
          }
      }
  
      public function getFlowProgressAttr($value, $data)
      {
          $bill = Config::get('database')['prefix'] . $this->name;
          $billId = isset($data['id']) ? $data['id'] : 0;
          try {
              return (new api())->getFlowProgress($bill, $billId);
          } catch (\Throwable $e) {
              return 0;
          }
      }
  }