0
0

GGoodsCate.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace app\common\model;
  3. use think\Db;
  4. class GGoodsCate extends Base
  5. {
  6. public function updates(){
  7. $data = request()->post();
  8. $data['org_id'] = cur_org_id();
  9. $result = validate('GGoodsCate')->check($data,[],'');
  10. if(true !== $result){
  11. $this->error = validate('GGoodsCate')->getError();
  12. return false;
  13. }
  14. $id = $data['id'];
  15. unset($data['id']);
  16. if($id > 0){
  17. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  18. }else{
  19. $data['create_time'] = date('Y-m-d H:i:s');
  20. $ret = $this->allowField(true)->save($data);
  21. }
  22. if(!$ret){
  23. $this->error = '操作失败';
  24. return false;
  25. }
  26. return true;
  27. }
  28. public function lists($orgId){
  29. $ret=Db::name('g_goods_cate')
  30. ->field('id,title')
  31. ->where(['org_id'=>$orgId,'enable'=>1])
  32. ->order(['sort'=>'asc','id'=>'desc'])
  33. ->select();
  34. $data=[
  35. [
  36. 'id'=>0,
  37. 'title'=>'全部'
  38. ],
  39. ];
  40. foreach ($ret as $k=>$v){
  41. $data[] = $v;
  42. }
  43. return $data;
  44. }
  45. }