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('提交上限申请失败,请重试')]);
 }
 public static function getUnableProducts($e, $products, $group, $user)
 {
     if (!count($products)) {
         $e->pass();
         return;
     }
     $confs = \Gini\Config::get('app.rpc');
     $conf = $confs['lab-inventory'];
     $rpc = \Gini\IoC::construct('\\Gini\\RPC', $conf['url']);
     $group_id = $group->id;
     $token = $rpc->mall->authorize($conf['client_id'], $conf['client_secret']);
     if (!$token) {
         $e->abort();
         return ['error' => H(T('存货管理连接中断'))];
     }
     foreach ($products as $info) {
         if ($info['customized']) {
             continue;
         }
         $product = a('product', $info['id']);
         if (!$product->cas_no) {
             continue;
         }
         $cas_no = $product->cas_no;
         $package = $product->package;
         $i = \Gini\Unit\Conversion::of($product);
         $ldata = self::_getCasVolume($i, $cas_no, $group_id);
         if ($ldata['error']) {
             $data[] = ['reason' => $ldata['error'], 'id' => $info['id'], 'name' => $product->name];
         }
         $volume = $ldata['volume'];
         $lNum = $i->from($volume)->to('g');
         if ((string) $volume === '') {
             continue;
         }
         // 如果设置为0不允许购买
         if ((string) $lNum === '0') {
             $data[] = ['reason' => H(T('该商品不允许购买')), 'id' => $info['id'], 'name' => $product->name];
         } elseif ($lNum) {
             $pdata = self::_getProductVolume($i, $package, $info['quantity']);
             if ($pdata['error']) {
                 $data[] = ['reason' => $pdata['error'], 'id' => $info['id'], 'name' => $product->name];
                 continue;
             }
             $idata = self::_getInventoryVolume($cas_no, $group_id);
             if ($idata['error']) {
                 $data[] = ['reason' => $idata['error'], 'id' => $info['id'], 'name' => $product->name];
                 continue;
             }
             $conf = self::_getHazConf($cas_no, $group_id);
             $count_cart = $conf['count_cart'];
             $iNum = $i->from($idata['volume'])->to('g');
             if ($count_cart) {
                 $pNum = $i->from($pdata['volume'])->to('g');
                 $sum = $iNum + $pNum;
             } else {
                 $sum = $iNum;
             }
             if ($sum > $lNum) {
                 $data[] = ['reason' => H(T('超出该商品的管控上限')), 'id' => $info['id'], 'name' => $product->name];
             }
         }
     }
     if (!empty($data)) {
         $e->abort();
         return $data;
     }
     $e->pass();
 }