123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- <?php
- namespace app\admin\model;
- use app\abutment\model\SupplierRelationUser as SupplierRelationUserModel;
- use app\abutment\model\SupplierUser as SupplierUserModel;
- use think\facade\Db;
- use think\Model;
- class ProcessWait extends Model
- {
- protected $table = 'wsm_process_wait';
- protected $pk = 'id';
- protected $autoWriteTimestamp = false;
- public static $status_wait = 1;
- public static $status_finish = 2;
- public static $status_interrupt = 3;
-
- public static function add(array $data = [], int $wait_id = 0, string $wait_name = '', string $handle_user_list = '')
- {
-
- Db::name('process_wait')
- ->where(['order_type' => $data['order_type'], 'order_code' => $data['order_code'], 'order_id' => $data['order_id']])
- ->update(['order_process_finally' => $data['action_process'], 'action_uid_finally' => $data['action_uid'], 'action_name_finally' => $data['action_name']]);
-
- Db::name('process_wait')
- ->where(['order_type' => $data['order_type'], 'order_process' => $data['action_status'], 'order_code' => $data['order_code'], 'order_id' => $data['order_id'], 'status' => self::$status_wait])
- ->update(['status' => self::$status_finish, 'updatetime' => date('Y-m-d H:i:s')]);
-
- $info = Db::name('process')
- ->alias('a')
- ->field('p.id,p.action_type,p.operation_type,a.api_url')
- ->join('action_process p', 'p.process_id=a.id AND p.order_process=' . $data['action_process'])
- ->where(['a.process_type' => $data['order_type'], 'a.status' => Process::$status_normal, 'a.is_del' => Process::$is_del_normal])
- ->findOrEmpty();
- if ($info) {
-
- if ($info['action_type'] == ActionProcess::$action_type_interrupt) {
- self::where(['order_type' => $data['order_type'], 'order_code' => $data['order_code'], 'order_id' => $data['order_id'], 'status' => self::$status_wait])
- ->update(['status' => self::$status_interrupt, 'updatetime' => date('Y-m-d H:i:s')]);
- return true;
- }
-
- if ($info['operation_type'] == ActionProcess::$operation_type_system) return true;
-
- if (in_array($data['order_type'], ['CKD', 'RKD', 'CGD'])) {
- switch ($data['order_type']) {
-
- case 'CKD':
- $supplierNo = Db::name('order_out')
- ->alias('a')
- ->leftJoin('order_num b', 'b.orderCode=a.orderCode')
- ->leftJoin('purchease_order c', 'c.cgdNo=b.cgdNo')
- ->where(['a.is_del' => 0, 'a.outCode' => $data['order_code']])
- ->value('c.supplierNo');
- break;
-
- case 'RKD':
- $supplierNo = Db::name('purchease_in')
- ->alias('a')
- ->leftJoin('purchease_order b', 'b.cgdNo=a.cgdNo')
- ->where(['a.is_del' => 0, 'a.wsm_in_code' => $data['order_code']])
- ->value('b.supplierNo');
- break;
-
- case 'CGD':
- $supplierNo = Db::name('purchease_order')
- ->where(['cgdNo' => $data['order_code'], 'is_del' => 0])
- ->value('supplierNo');
- break;
- default:
- $supplierNo = '';
- break;
- }
- if ($supplierNo) {
-
- $res = SupplierRelationUserModel::field('id')
- ->where([
- 'is_del' => SupplierUserModel::$is_del_normal,
- 'supplierNo' => $supplierNo,
- 'status' => SupplierUserModel::$status_normal
- ])
- ->findOrEmpty()
- ->isEmpty();
- if (!$res) return true;
- }
- }
-
- if ($data['order_type'] == 'SPCB' && !in_array($data['action_process'], [0, 2, 3])) return true;
- $insert_data = [
- 'order_type' => $data['order_type'],
- 'order_code' => $data['order_code'],
- 'order_id' => $data['order_id'],
- 'action_uid' => $data['action_uid'],
- 'action_name' => $data['action_name'],
- 'status' => self::$status_wait,
- 'order_process' => $data['action_process'],
- 'order_process_finally' => $data['action_process'],
- 'action_uid_finally' => $data['action_uid'],
- 'action_name_finally' => $data['action_name'],
- 'addtime' => date('Y-m-d H:i:s'),
- 'updatetime' => date('Y-m-d H:i:s'),
- ];
- if ($wait_id) {
- $insert_data['handle_user_list'] = $wait_id;
- $insert_data['wait_id'] = $wait_id;
- $insert_data['wait_name'] = $wait_name;
- } else {
-
- $roleid = Db::name('role_process')
- ->whereFindInSet('action_data', $info['id'])
- ->where('is_del', 0)
- ->column('role_id');
- $insert_data['roleid'] = implode(',', $roleid);
-
- if ($data['order_type'] == 'YJD' && $data['action_process'] == 7) $insert_data['handle_user_list'] = implode(',', Db::name('user_role')->whereIn('roleid', $roleid)->where(['is_del' => 0, 'status' => 1])->where('roleid', '<>', 1)->column('uid'));
- else $insert_data['handle_user_list'] = $handle_user_list ? $handle_user_list : implode(',', get_handle_user_list($info['id'], $data['holder_id'] ?? 0, $info['api_url'], $data['person_id'] ?? 0));
- }
-
- return self::create($insert_data)->save();
- }
- return true;
- }
- }
|