コード例 #1
0
 public function actionSubmitApplication()
 {
     $me = _G('ME');
     $group = _G('GROUP');
     if (!$me->id || !$group->id || !$me->isAllowedTo('设置')) {
         return;
     }
     $form = $this->form('post');
     $type = trim($form['type']);
     $casNO = trim($form['cas_no']);
     $volume = trim($form['volume']);
     $reason = trim($form['reason']);
     if (!$reason) {
         return \Gini\IoC::construct('\\Gini\\CGI\\Response\\JSON', ['code' => 1, 'message' => T('请填写申请理由')]);
     }
     $title = \Gini\ORM\ChemicalLimits\Request::getTypeTtile($type);
     if (!$type || !$title) {
         return \Gini\IoC::construct('\\Gini\\CGI\\Response\\JSON', ['code' => 2, 'message' => T('请选择分类')]);
     }
     if ($casNO) {
         $chemInfo = \Gini\ChemDB\Client::getChemicalInfo($casNO);
         if (empty($chemInfo)) {
             return \Gini\IoC::construct('\\Gini\\CGI\\Response\\JSON', ['code' => 3, 'message' => T('请重新选择化学品')]);
         }
         $chem = ['cas' => $casNO, 'state' => $chemInfo['state'], 'default'];
     } else {
         $chem = ['default'];
     }
     if (!\Gini\Unit\Conversion::of($chem)->validate($volume)) {
         return \Gini\IoC::construct('\\Gini\\CGI\\Response\\JSON', ['code' => 4, 'message' => T('上限设置格式错误,请输入数字+单位,例5mg(目前系统支持单位: 瓶/bottle/ml/g/cm3/ul/μl/ml/cl/dl/l/gal/lb/ug/μg/mg/kg/oz/lb/)')]);
     }
     $rpc = \Gini\Module\HazardousControlOrders::getRPC('chemical-limits');
     $result = (bool) $rpc->admin->inventory->addRequest(['type' => $type, 'cas_no' => $casNO, 'volume' => $volume, 'group_id' => $group->id, 'owner_id' => $me->id, 'reason' => $reason]);
     return \Gini\IoC::construct('\\Gini\\CGI\\Response\\JSON', ['code' => $result ? 0 : 5, 'message' => $result ? T('上限申请提交成功') : T('提交上限申请失败,请重试')]);
 }
コード例 #2
0
 private function _getProductTypes($type, $subType = null, $cas = null)
 {
     $result = [];
     if ($cas) {
         if (isset(self::$data[$cas])) {
             $data = self::$data[$cas];
         } else {
             self::$data[$cas] = $data = \Gini\ChemDB\Client::getChemicalInfo($cas);
         }
         if (is_array($data)) {
             $result[] = $data['types'];
             $result[] = $type;
         }
         if (!empty($result)) {
             return $result;
         }
     }
     $types = [\Gini\ORM\Product::RGT_TYPE_NORMAL => 'normal', \Gini\ORM\Product::RGT_TYPE_HAZARDOUS => 'hazardous', \Gini\ORM\Product::RGT_TYPE_DRUG_PRECURSOR => 'drug_precursor', \Gini\ORM\Product::RGT_TYPE_HIGHLY_TOXIC => 'highly_toxic', \Gini\ORM\Product::RGT_TYPE_EXPLOSIVE => 'explosive'];
     if ($subType && isset($types[$subType])) {
         $result[] = $types[$subType];
     }
     $result[] = $type;
     return $result;
 }