Ejemplo n.º 1
0
 public function quickAddSample($get, $post)
 {
     if ($post) {
         $ex = Model::transaction(function () use($post) {
             $sample = new Sample();
             $sample->setValues(array('sample_type' => $post['sample_type'], 'category_id' => $post['category_id'], 'material_id' => $post['material_id'], 'sample_no' => $post['sample_no'], 'chinese_name' => $post['chinese_name']));
             $sample->save();
             if ($post['sample_type'] == GlobalConf::SAMPLE_TYPE_SINGLE) {
                 $ss = new SingleSample();
                 $ss->sample_id = $sample->id;
                 $ss->technic_flow_id_list = $post['technic_flow_id_list'];
                 $ss->save();
             }
             $si = new SampleImage();
             $si->setValues(array('sample_id' => $sample->id, 'image_url' => $post['image_url']));
             $si->save();
             $sp = new SamplePackage();
             $sp->setValues(array('sample_id' => $sample->id, 'pack_name' => $post['pack_name'], 'pack_desc' => $post['pack_desc']));
             $sp->save();
         });
         if ($ex) {
             return new Result($ex->getMessage());
         } else {
             return new Result('样品添加成功', true, $post['sample_no']);
         }
     }
     $tmp = SampleCategory::find()->all(true);
     $tmp = array_filter_subtree(0, $tmp);
     foreach ($tmp as $k => $item) {
         $tmp[$k]['name'] = str_repeat(' ', $item['tree_level'] * 5) . '|-' . $item['name'];
     }
     $category_list = array_combine(array_column($tmp, 'id'), array_column($tmp, 'name'));
     $material_list = SampleMaterial::find('state=?', SampleMaterial::STATE_ENABLED)->all();
     return array('material_list' => $material_list, 'category_list' => $category_list);
 }