<?php

/* ========================================================================
 * $Id: edit.php 2212 2020-07-08 09:11:19Z onez $
 * 
 * Email: www@onez.cn
 * QQ: 6200103
 * HomePage: http://www.onez.cn
 * ========================================================================
 * Copyright 2016-2017 佳蓝科技.
 * 
 * ======================================================================== */

!defined('IN_ONEZ') && exit('Access Denied');
# edit
#请求数据
if($MODE=='$post'){
  $id=onez()->gp('id');
  $action=onez()->gp('action');
  if($action=='data'){

    $form=$this->load('form');
    if($id){
      $T=$G['this']->data()->open('products')->one("id='$id'");
      #$T['message']=onez('bs.app.shipments')->strcode($T['message'],'DECODE');
      $form->init($T);
    }
    $options=array();
    $T=$G['this']->data()->open('categorys')->record("key2='card' order by step desc,id desc");
    foreach($T as $rs){
      $options[$rs['id']]=$rs['name'];
    }
    $form->add(array('label'=>'所属分类','key'=>'upid','type'=>'select','options'=>$options,'hint'=>'','group'=>'',));
    $form->add(array('label'=>'商品名称','key'=>'name','type'=>'text','notempty'=>'名称不能为空','hint'=>'','group'=>'',));
    $form->add(array('label'=>'商品编码','key'=>'token','type'=>'text','notempty'=>'','hint'=>'','group'=>'',));
    $form->add(array('label'=>'缩略图','key'=>'thumb','type'=>'image','notempty'=>'','hint'=>'','group'=>'',));
    $form->add(array('label'=>'优先级','key'=>'step','type'=>'text','notempty'=>'','hint'=>'','group'=>'',));
    $form->add(array('label'=>'价格','key'=>'price','type'=>'text','notempty'=>'','hint'=>'','group'=>'',));
    
    #$form->add(array('label'=>'卡密内容','key'=>'message','ptoken'=>'bs.editor','notempty'=>'','hint'=>'','group'=>'',));
    $form->add(array('label'=>'内容详情','key'=>'content','ptoken'=>'bs.editor','notempty'=>'','hint'=>'','group'=>'',));
    
    if($onez=$form->submit()){
      $onez['key1']=$onez['name'];
      $onez['money1']=$onez['price'];
      #$onez['message']=onez('bs.app.shipments')->strcode($_REQUEST['message'],'ENCODE');
      $onez['content']=$_REQUEST['content'];
      if($id){
        $G['this']->data()->open('products')->update($onez,"id='$id'");
      }else{
        $onez['userid']=$G['userid'];
        $onez['key2']='card';
  
        $G['this']->data()->open('products')->insert($onez);
      }
      return $this->ok('提交成功','reload2');
    }
    $form->output($A);
  }
  return;
}
$this->add(array(
  'type'=>'pageform',
  'name'=>'表单',
  'data'=>'$form',
));
?>