identityVerify($param); if ($verifyResult['status'] != 1) { return $verifyResult; } if (empty($param['company_arr'])) { return callBack(statusCode()['error'], '请传入单位'); } $arr = json_decode($param['company_arr'], true); if (!is_array($arr)) { return callBack(statusCode()['error'], '单位格式有误'); } $where = [ 'state' => 1, ]; $data = [ 'state' => 1, 'merchant_id' => $param['merchant_id'], 'add_time' => $_SERVER['REQUEST_TIME'] ]; switch ($param['user_type']) { case 3: $where[] = [ [ 'merchant_id' => $param['merchant_id'], 'type'=>1 ], [ 'type'=>0 ], '_logic'=>'or' ]; $data['type'] = 1; break; case 4: $where[] = [ [ 'store_id'=>$param['store_id'], 'merchant_id'=>$param['merchant_id'], 'type'=>2 ], [ 'type'=>0 ], '_logic'=>'or' ]; $data['type'] = 2; $data['store_id'] = $param['store_id']; break; } $new_arr = []; try { M()->startTrans(); $UnitModel = new UnitLibraryModel(); $list = $UnitModel->getFindField($where,'name',true); $list = $list?$list:[]; foreach ($arr as $val) { if (!in_array($val,$list)) { //不存在的 $list[] = $val; $data['name'] = $val; $new_arr[] = $data; } } if (!empty($new_arr)) { $id = $UnitModel->addAll($new_arr); if ($id) { M()->commit(); return callBack(statusCode()['success'], '单位添加成功'); } else { M()->rollback(); return callBack(statusCode()['error'], '单位添加失败'); } } M()->commit(); return callBack(statusCode()['success'], '暂无可添加单位'); } catch (\Exception $e) { return callBack(statusCode()['success'], '暂无可添加单位'); } } }