123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- <?php
- namespace app\store\controller;
- use library\Controller;
- use think\Db;
- /**
- * 积分商品
- * Class Goods
- * @package app\store\controller
- */
- class IntegralGoods extends Controller
- {
- /**
- * 绑定数据表
- * @var string
- */
- protected $table = 'StoreGoods';
- /**
- * 商品列表
- * @auth true
- * @menu true
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function index()
- {
- $this->title = '商品管理';
- $query = $this->_query($this->table)->where('is_deleted',0)->where(['is_integral'=>1])->like('name');
- $query->dateBetween('create_at')->order('sort desc , id desc')->page();
- }
- /**
- * 数据列表处理
- * @auth true
- * @menu true
- * @param array $data
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- protected function _index_page_filter(&$data)
- {
- foreach ($data as $k=>&$v){
- }
- }
- /**
- * 添加商品
- * @auth true
- * @menu 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 = '添加商品';
- $lev_set = Db::table('member_level')->field('id,name')->select();
- $lev_set = array_column($lev_set,null,'id');
- $lev_data = ['0'=>'不限'];
- array_map(function ($v)use (&$lev_data){
- $lev_data[$v['id']] = $v['name'];
- },$lev_set);
- $this->lev_set =$lev_data;
- // 分类
- $goods_cate = Db::table('store_goods_cate')
- ->field('id,title')
- ->where(['is_deleted'=>0,'status'=>1,'pid'=>0])
- ->order('sort desc ,id desc')
- ->select();
- array_walk($goods_cate,function (&$v){
- $v['children'] =Db::table('store_goods_cate')
- ->where(['is_deleted'=>0,'status'=>1,'pid'=>$v['id']])
- ->order('sort desc ,id desc')
- ->select();
- });
- $this->goods_cate = $goods_cate;
- $this->all_temp = Db::table('freight_template')
- ->field('id,name')->where(['status'=>1,'is_deleted'=>0])
- ->order('sort desc ,id desc')->select();
- $this->_form($this->table, 'form');
- }
- /**
- * 编辑商品
- * @auth true
- * @menu true
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- function edit()
- {
- $this->title = '编辑商品';
- $lev_set = Db::table('member_level')->field('id,name')->select();
- $lev_set = array_column($lev_set,null,'id');
- $lev_data = ['0'=>'不限'];
- array_map(function ($v)use (&$lev_data){
- $lev_data[$v['id']] = $v['name'];
- },$lev_set);
- $this->lev_set =$lev_data;
- // 分类
- $goods_cate = Db::table('store_goods_cate')
- ->field('id,title')
- ->where(['is_deleted'=>0,'status'=>1,'pid'=>0])
- ->order('sort desc ,id desc')
- ->select();
- array_walk($goods_cate,function (&$v){
- $v['children'] =Db::table('store_goods_cate')
- ->where(['is_deleted'=>0,'status'=>1,'pid'=>$v['id']])
- ->order('sort desc ,id desc')
- ->select();
- });
- $this->goods_cate = $goods_cate;
- // 规格
- $goods_spec = Db::table('store_goods_specifica')
- ->field('id,title,detail')
- ->where(['is_deleted'=>0])
- ->order('sort desc ,id desc')
- ->select();
- array_walk($goods_spec,function (&$val){
- // $val['detail'] = json_decode($val['detail']);
- });
- $goods_spec = array_column($goods_spec,null,'id');
- $this->goods_spec = $goods_spec;
- $this->all_temp = Db::table('freight_template')
- ->field('id,name')->where(['status'=>1,'is_deleted'=>0])
- ->order('sort desc ,id desc')->select();
- $this->_form($this->table, 'form');
- }
- /**
- * 表单数据处理
- * @auth true
- * @menu true
- * @param array $data
- */
- protected function _form_filter(&$data)
- {
- if($this->request->isGet()){
- if($this->request->action() == 'edit') {
- if($data['spec']) $data['spec'] = json_decode($data['spec'],true);
- }
- }
- // 添加或编辑商品
- if ($this->request->isPost()) {
- $spec_count = count($data['goods_no']);
- $goods_spec = [];
- $detail_list = [];
- if(isset($data['spec_id']) && $data['spec_id'] > 0) {
- $spec_info = Db::table('store_goods_specifica')->find($data['spec_id'] );
- $detail_list = $spec_info['detail'] ? json_decode($spec_info['detail']) : [];
- }
- $total_num = 0;
- for ($i= 0;$i < $spec_count;$i++) {
- $goods_spec[$i]['goods_no'] = $data['goods_no'][$i];
- $goods_spec[$i]['spec_img'] = $data['cover'];
- $goods_spec[$i]['store_num'] = $data['store_num'][$i] > 0 ?$data['store_num'][$i] :0 ;
- $goods_spec[$i]['price'] = $data['price'][$i] >0 ? $data['price'][$i] :0; ['price'][$i] >0 ? $data['price'][$i] :0 ;
- $goods_spec[$i]['integral'] = $data['integral'][$i] >0 ? $data['integral'][$i] :0; ['price'][$i] >0 ? $data['price'][$i] :0 ;
- $goods_spec[$i]['sell_money'] = 0;
- $goods_spec[$i]['seckill_money'] = 0;
- $goods_spec[$i]['spec_exp'] = '';
- $goods_spec[$i]['spec_key'] = '';
- $total_num +=$goods_spec[$i]['store_num'] ;
- }
- $data['spec'] =json_encode($goods_spec);
- $data['stock'] =$total_num; // 总库存
- $data['floor_price'] = min( array_column($goods_spec,'sell_money') );// 最低价
- $data['integral'] = $data['integral'][0];
- $data['is_integral'] = 1;
- }
- }
- /**
- * @auth true
- * @menu true
- * 商品上架
- */
- public function up()
- {
- $this->_save($this->table, ['status' => '1']);
- }
- /**
- * @auth true
- * @menu true
- * 商品下架
- */
- public function down()
- {
- $this->_save($this->table, ['status' => '0']);
- }
- /**
- * @auth true
- * @menu true
- * 商品下架
- */
- public function del()
- {
- $this->_save($this->table, ['is_deleted' => '1']);
- }
- public function upload(){
- if(!in_array($_FILES["file"]["type"],['image/png','image/jpeg','image/jpeg'])) echo '图片类型不支持';
- if($_FILES["file"]["size"] > 50000000) echo '图片大小最大50M';
- if ($_FILES["file"]["error"] > 0) echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
- // $dir = env('root_path') . 'public/static/pic';
- $dir = $_SERVER['DOCUMENT_ROOT']. '/static/pic';
- /* var_dump($dir);
- if(!is_dir($dir)) {
- var_dump(mkdir($dir));
- }*/
- move_uploaded_file($_FILES["file"]["tmp_name"], $dir."/" . $_FILES["file"]["name"]);
- echo $dir."/" . $_FILES["file"]["name"];
- }
- }
|