123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2020-08-28
- * Time: 14:58
- */
-
- namespace app\back\controller;
-
-
- use app\back\model\GoodsCategoryModel;
- use app\back\model\GoodsModel;
- use cmf\controller\AdminBaseController;
- class GoodsController extends AdminBaseController
- {
- public function index()
- {
- $where = [];
- $pw = [];
- $page = $this->request->param('page',1);
- $list = GoodsModel::with('category')->where($where)->order('list_order','asc')->paginate(30,false,array($page,url('index'),'query'=>$pw));
- $this->assign('list',$list);
- return $this->fetch();
- }
- public function add()
- {
- $goodsCategoryList = GoodsCategoryModel::where('is_show',1)->order('list_order','asc')->select();
- $this->assign('goodsCategoryList',$goodsCategoryList);
-
- return $this->fetch();
- }
- public function addPost()
- {
- $data = $this->request->param();
-
- if (!empty($data['photo_names']) && !empty($data['photo_urls'])) {
- $data['banner'] = [];
- foreach ($data['photo_urls'] as $key => $url) {
- $photoUrl = cmf_asset_relative_url($url);
- array_push( $data['banner'], ["url" => $photoUrl, "name" => $data['photo_names'][$key]]);
- }
- }
-
- unset($data['photo_urls']);
- unset($data['photo_names']);
- $goodsModel = new GoodsModel();
- $goodsModel->allowField(true)->isUpdate(false)->save($data);
- $this->success('添加成功');
- }
- public function edit()
- {
- $id = $this->request->param('id');
- $info = GoodsModel::get($id,'category');
- $this->assign('info',$info);
-
- $goodsCategoryList = GoodsCategoryModel::where('is_show',1)->where('id','<>',$info->category_id)->order('list_order','asc')->select();
- $this->assign('goodsCategoryList',$goodsCategoryList);
- return $this->fetch();
- }
- public function editPost()
- {
- $data = $this->request->param();
-
- if (!empty($data['photo_names']) && !empty($data['photo_urls'])) {
- $data['banner'] = [];
- foreach ($data['photo_urls'] as $key => $url) {
- $photoUrl = cmf_asset_relative_url($url);
- array_push( $data['banner'], ["url" => $photoUrl, "name" => $data['photo_names'][$key]]);
- }
- }
-
- unset($data['photo_urls']);
- unset($data['photo_names']);
- $goodsModel = new GoodsModel();
- $goodsModel->allowField(true)->isUpdate(true)->save($data);
- $this->success('编辑成功');
- }
- public function delete()
- {
- $id = $this->request->param('id');
- GoodsModel::destroy($id);
- $this->success('删除成功');
- }
-
-
- public function shelves()
- {
- $ids = $this->request->param('ids/a');
- $shelves = $this->request->param('shelves');
- GoodsModel::where('id','in',$ids)->update(['shelves'=>$shelves]);
- $this->success('操作成功');
- }
-
- public function is_sell()
- {
- $ids = $this->request->param('ids/a');
- $is_sell = $this->request->param('is_sell');
- GoodsModel::where('id','in',$ids)->update(['is_sell'=>$is_sell]);
- $this->success('操作成功');
- }
-
- public function listOrder()
- {
- $GoodsModel = new GoodsModel();
- parent::listOrders($GoodsModel);
- $this->success("排序更新成功!");
- }
-
- public function select()
- {
- $id = $this->request->param('id');
- $list = GoodsModel::where('shelves',1)->order('list_order','asc')->field('id,goods_name,price,seckill_price,repertory')->select();
- $this->assign('list',$list);
- $this->assign('id',$id);
- return $this->fetch();
-
- }
- }
|