123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- <?php
- // +----------------------------------------------------------------------
- // | ThinkAdmin
- // +----------------------------------------------------------------------
- // | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
- // +----------------------------------------------------------------------
- // | 官方网站: http://demo.thinkadmin.top
- // +----------------------------------------------------------------------
- // | 开源协议 ( https://mit-license.org )
- // +----------------------------------------------------------------------
- // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
- // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
- // +----------------------------------------------------------------------
- namespace app\approve\controller;
- use app\common\constant\CommonConstant;
- use app\common\model\Goods as model;
- use app\common\model\GoodsStock;
- use app\common\service\GoodsCategoryService;
- use library\Controller;
- use library\tools\Data;
- use think\Db;
- /**
- * 商品
- */
- class Goods extends Controller
- {
- /**
- * 绑定数据表
- * @var string
- */
- protected $table = 'Goods';
- /**
- * 控制器初始化
- */
- protected function initialize()
- {
- $this->get_status_list = CommonConstant::get_status_list();
- }
- /**
- * 列表
- * @auth true
- * @menu true
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function index()
- {
- $status = input('status');
- $goods_name = input('goods_name');
- $this->title = '商品列表';
- $data = model::field('is_deleted', true)
- ->where('is_deleted', CommonConstant::IS_DELETED_0)
- ->when(array_key_exists($status, $this->get_status_list), function ($query) use ($status) {
- $query->where('status', $status);
- })
- ->when($goods_name,function ($query) use($goods_name){
- $query->where('goods_name','like','%'.$goods_name.'%');
- })
- ->with([
- 'goodsCategoryOne'=>function($query){
- $query->field('id,name');
- },
- 'goodsCategory'=>function($query){
- $query->field('id,name');
- },
- 'goodsStock'
- ])
- ->order('sort desc,id asc');
- self::_init($data);
- }
- /**
- * 添加
- * @auth true
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function add()
- {
- $this->title = '添加';
- $this->_form($this->table, 'form');
- }
- /**
- * 编辑
- * @auth true
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function edit()
- {
- $this->title = '编辑';
- $this->_form($this->table, 'form');
- }
- /**
- * 表单处理
- * @param array $data
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- protected function _form_filter(&$data)
- {
- if ($this->request->isGet()) {
- if($data){
- // 编辑获取数据时
- $data['first_classify'] = $data['goods_category_first'];
- $data['second_classify'] = $data['goods_category_id'];
- $data['goods_stock'] = GoodsStock::where('goods_id',$data['id'])->select();
- }
- $this->category_list = GoodsCategoryService::get_list([],1);
- }
- if ($this->request->isPost()) {
- if($data){
- // 编辑提交数据时
- $data['goods_category_first'] = $data['first_classify'];
- $data['goods_category_id'] = $data['second_classify'];
- }
- }
- }
- /**
- * 表单结果处理
- * @param boolean $result
- */
- protected function _form_result($result)
- {
- if ($result && $this->request->isPost()) {
- list($data) = [$this->request->post()];
- p($result);
- p($data);
- exit;
- // $data['id'] = $result;
- // $low_price = 0;
- // foreach (json_decode($data['lists'], true) as $ko=>$vo){
- // if($low_price == 0 || $vo[0]['sell_price'] < $low_price )$low_price = $vo[0]['sell_price'];
- // Data::save('StoreGoodsItem', [
- // 'goods_id' => $data['id'],
- // 'spec_cover' => $data['spec_cover'][$ko] ? $data['spec_cover'][$ko] : $vo[0]['spec_cover'],
- // 'goods_spec' => $vo[0]['key'],
- // 'goods_no' => $vo[0]['sku'],
- // 'original_price' => $vo[0]['original_price'],
- // 'sell_price' => $vo[0]['sell_price'],
- // 'virtual' => $vo[0]['virtual'],
- // 'status' => $vo[0]['status'] ? 1 : 0,
- // 'weight' => $vo[0]['weight'] ? $vo[0]['weight'] : 0,
- // ], 'goods_spec', ['goods_id' => $data['id']]);
- // }
- // Db::name('StoreGoods')->where(['id'=>$data['id']])->update(['low_price'=>$low_price]);
- // \app\common\model\StoreGoods::esAdd($result);
- // \app\common\model\TopSearch::saveData($result,'goods');
- $this->success('商品编辑成功!', 'javascript:history.back()');
- }
- }
- /**
- * 删除
- * @auth true
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- */
- public function remove()
- {
- $this->applyCsrfToken();
- $this->_delete($this->table);
- }
- /**
- * 启用
- * @auth true
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- */
- public function resume()
- {
- $this->applyCsrfToken();
- $this->_save($this->table, ['status' => CommonConstant::STATUS_NORMAL]);
- }
- /**
- * 禁用
- * @auth true
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- */
- public function forbid()
- {
- $this->applyCsrfToken();
- $this->_save($this->table, ['status' => CommonConstant::STATUS_FROZEN]);
- }
- }
|