123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- <?php
- namespace Scm_role\Lib;
- use Dever;
- class Seller
- {
- # 获取商品列表
- public function getGoods($seller_id)
- {
- $where['seller_id'] = $seller_id;
- $where['sell_type'] = 1;
- $data = Dever::db('scm_role/seller_goods')->getDataPage($where);
- if ($data) {
- foreach ($data as $k => $v) {
- $v['id'] = $v['goods_id'];
- $data[$k] = Dever::load('scm_product/lib/info')->getInfo($v);
- }
- }
- return $data;
- }
- # 采购商品
- public function buyGoods_api()
- {
- $data = array();
- $data['seller_id'] = Dever::input('id', 1);
- $info = Dever::db('scm_role/seller')->find($data['seller_id']);
- $data['info'] = $info;
- $goods_category = $info['category'];
- $data['host'] = Dever::url('lib/seller.buyGoods', 'scm_role');
- $data['url'] = Dever::url('lib/seller.goods?seller_id=' . $data['seller_id'] . '&goods_category=' . $goods_category . '&price_id=' . $info['price_id'] . '&type=2', 'scm_role');
- $data['submit'] = Dever::url('lib/seller.buyGoods_action_commit?json=1', 'scm_role');
- return Dever::render('buy_seller_goods', $data);
- }
- # 采购商品
- public function buyGoods_action_commit_api()
- {
- $goods = Dever::input('goods');
- if (!$goods) {
- Dever::alert('请传入商品');
- }
- $goods = Dever::json_decode($goods);
- $seller_id = Dever::input('seller_id');
- $seller = Dever::db('scm_role/seller')->one($seller_id);
- $where['option_seller_id'] = $seller_id;
- $where['set_state'] = 2;
- Dever::db('scm_role/seller_goods')->updates($where);
- Dever::db('scm_role/seller_goods_sku')->updates($where);
- foreach ($goods as $k => $v) {
- $temp = explode('-', $k);
- $goods_id = $temp[0];
- if (isset($temp[1])) {
- $sku_id = $temp[1];
- } else {
- $sku_id = -1;
- }
- if ($v['num'] < 0) {
- continue;
- }
- if ($v['del'] == 2) {
- $w = array();
- $w['goods_id'] = $goods_id;
- $w['seller_id'] = $seller_id;
- $w['sku_id'] = $sku_id;
- $sku_info = Dever::db('scm_role/seller_goods_sku')->one($w);
- if ($sku_info) {
- Dever::db('scm_role/seller_goods_sku')->update(array('where_id' => $sku_info['id'], 'state' => 2));
- }
- unset($w['sku_id']);
- $t = $w;
- $t['state'] = 1;
- $total = Dever::db('scm_role/seller_goods_sku')->total($t);
- if ($total <= 0) {
- $info = Dever::db('scm_role/seller_goods')->one($w);
- if ($info) {
- Dever::db('scm_role/seller_goods')->update(array('where_id' => $info['id'], 'state' => 2));
- }
- }
- } else {
- $goods_info = Dever::db('scm_product/info')->one($goods_id);
- $w = array();
- $w['goods_id'] = $goods_id;
- $w['seller_id'] = $seller_id;
- $info = Dever::db('scm_role/seller_goods')->one($w);
- $w['in_num'] = $v['num'];
- $w['min'] = $v['min'];
- if (!$info) {
- Dever::db('scm_role/seller_goods')->insert($w);
- } else {
- $w['in_num'] += $info['in_num'];
- $w['where_id'] = $info['id'];
- $w['state'] = 1;
- Dever::db('scm_role/seller_goods')->update($w);
- }
- $w = array();
- $w['goods_id'] = $goods_id;
- $w['seller_id'] = $seller_id;
- $w['sku_id'] = $sku_id;
- $info = Dever::db('scm_role/seller_goods_sku')->one($w);
- $w['in_num'] = $v['num'];
- $w['min'] = $v['min'];
- if (!$info) {
- Dever::db('scm_role/seller_goods_sku')->insert($w);
- } else {
- $w['in_num'] += $info['in_num'];
- $w['where_id'] = $info['id'];
- $w['state'] = 1;
- Dever::db('scm_role/seller_goods_sku')->update($w);
- }
- }
- }
- return 'refer';
- }
- }
|