Exemplo n.º 1
0
 public function __construct($data = array())
 {
     parent::__construct($data);
     $this->setPropertiesDefine(array('sample_type_name' => array('getter' => function (Sample $item) {
         return GlobalConf::$sample_type_desc_map[$item->sample_type];
     }), 'sample_list' => array('getter' => function (Sample $item) {
         if ($item->sample_type != GlobalConf::SAMPLE_TYPE_SUITE) {
             throw new \Exception('样品不属于套件');
         }
         $tmp = SuiteSampleMapSingleSample::find('suite_sample_id=?', $item->id)->all(true);
         $sample_id_list = array_column($tmp, 'single_sample_id');
         return Sample::findByPks($sample_id_list);
     }), 'material_id' => array('options' => function () {
         $tmp = SampleMaterial::find('state=?', SampleMaterial::STATE_ENABLED)->all(true);
         return array_combine(array_column($tmp, 'id'), array_column($tmp, 'name'));
     }, 'display' => function (self $item = null) {
         $tmp = SampleMaterial::findOneByPk($item->material_id);
         if (!$tmp) {
             return '';
         }
         return $tmp->state == SampleMaterial::STATE_ENABLED ? $tmp->name : '<del>' . $tmp->name . '</del>';
     }), 'category_id' => array('options' => function () {
         $tmp = SampleCategory::find('state=?', SampleCategory::STATE_ENABLED)->all(true);
         $tmp = array_filter_subtree(0, $tmp);
         foreach ($tmp as $k => $item) {
             $tmp[$k]['name'] = str_repeat('&nbsp;', $item['tree_level'] * 5) . '|-' . $item['name'];
         }
         return array_combine(array_column($tmp, 'id'), array_column($tmp, 'name'));
     }, 'display' => function (self $item = null) {
         if ($item->category_id) {
             $tmp = SampleCategory::findOneByPk($item->category_id);
             if (!$tmp) {
                 return '';
             }
             return $tmp->state == SampleCategory::STATE_ENABLED ? $tmp->name : '<del>' . $tmp->name . '</del>';
         }
         return '';
     }), 'extend_info' => array('getter' => function (Sample $item) {
         if ($item->sample_type != GlobalConf::SAMPLE_TYPE_SINGLE) {
             throw new \Exception('样品不属于单品');
         }
         return SingleSample::find('sample_id=?', $item->id)->one() ?: new SingleSample(array('sample_id' => $item->id));
     }), 'produce_data' => array('getter' => function (Sample $item) {
         if ($item && $item->sample_type == GlobalConf::SAMPLE_TYPE_SINGLE) {
             return SampleProduceData::find('sample_id=?', $item->id)->one();
         }
         return null;
     }), 'first_image_src' => array('getter' => function (Sample $item) {
         return SampleImage::find('sample_id=?', $item->id)->ceil('image_url');
     }, 'rel' => 'upload-image'), 'key_words' => array('rel' => 'keywords'), 'tags' => array('rel' => 'tags'), 'package_list' => array('getter' => function (Sample $item) {
         return SamplePackage::find('sample_id = ?', $item->id)->all();
     })));
 }
Exemplo n.º 2
0
 public function update($get, $post)
 {
     $current_category = $get['id'] ? SampleCategory::findOneByPk($get['id']) : new SampleCategory();
     if ($post) {
         $current_category->setValues($post);
         $current_category->save();
         return $this->getCommonResult(true);
     }
     $tmp = SampleCategory::find()->all(true);
     $tmp = array_filter_subtree(0, $tmp);
     $all = array();
     foreach ($tmp as $item) {
         $item['name'] = str_repeat('&nbsp;', $item['tree_level'] * 5) . '|-' . $item['name'];
         if ($item['id'] == $current_category->id) {
             $current_category->tree_level = $item['tree_level'];
         }
         $all[] = new SampleCategory($item);
     }
     return array('all_categories' => $all, 'current_category' => $current_category);
 }
Exemplo n.º 3
0
 /**
  * @param $data
  * @param $current
  * @param array $opt
  * @return string
  */
 public static function generateParentTreeSelector($data, $current, $opt = array())
 {
     $opt = array_merge(array('return_as_tree' => false, 'level_key' => 'tree_level', 'id_key' => 'id', 'name_key' => 'name', 'parent_id_key' => 'parent_id', 'children_key' => 'children'), $opt);
     $data = array_filter_subtree(0, $data, $opt);
     /** @var array $data */
     $data = array_group($data, $opt['id_key'], true);
     $match = false;
     foreach ($data as $k => $item) {
         if ($item[$opt['id_key']] == $current[$opt['id_key']]) {
             $match = true;
             $data[$k]['__current__'] = true;
         } else {
             if ($match && $item[$opt['level_key']] <= $current[$opt['level_key']]) {
                 $match = false;
             } else {
                 if ($match && $item[$opt['level_key']] > $current[$opt['level_key']]) {
                     $data[$k]['__belongs__'] = true;
                 } else {
                     $match = false;
                 }
             }
         }
         $data[$k]['tree_name'] = str_repeat('&nbsp;', $item[$opt['level_key']] * 5) . '|-' . $item[$opt['name_key']];
     }
     $html = '<select size="1" name="' . $opt['parent_id_key'] . '">';
     $html .= '<option value="0">顶级</option>';
     foreach ($data as $item) {
         $html .= '<option value="' . $item[$opt['id_key']] . '" ' . ($item[$opt['id_key']] == $current[$opt['parent_id_key']] ? 'selected="selected"' : '') . ($item['__belongs__'] || $item['__current__'] ? ' disabled="disabled"' : '') . '>' . $item['tree_name'] . '</option>';
     }
     $html .= '</select>';
     return $html;
 }
Exemplo n.º 4
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('&nbsp;', $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);
 }