123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <?php
- namespace Scm_order\Lib;
- use Dever;
- class Set
- {
- # 获取商品列表
- public function goods_api()
- {
- $id = Dever::input('id', 1);
- $role = Dever::input('role');
- $price_id = Dever::input('price_id', -1);
- $source = 'scm_role/'.$role.'_goods_sku';
- $table = '';
- $goods_category = Dever::input('goods_category');
- $where[$role . '_id'] = $id;
- return Dever::outDiy(Dever::load('scm_product/lib/info')->getSetList($table, $where, $goods_category, 'goods_id', array(), $price_id, $source));
- }
- # 配置商品
- public function home_api()
- {
- $data = array();
- $data['id'] = Dever::input('id', 1);
- $data['role'] = Dever::input('role');
- $info = Dever::db('scm_role/' . $data['role'])->find($data['id']);
- $data['info'] = $info;
- $data['host'] = Dever::url('lib/set.home', 'scm_role');
- $uri = 'lib/set.goods?id=' . $data['id'] . '&role=' . $data['role'];
- if (isset($info['category'])) {
- $uri .= '&goods_category=' . $info['category'];
- }
- if (isset($info['price_id'])) {
- $uri .= '&price_id=' . $info['price_id'];
- }
- $data['url'] = Dever::url($uri, 'scm_role');
- $data['submit'] = Dever::url('lib/set.action_commit?json=1', 'scm_role');
- return Dever::render('set_' . $data['role'] . '_goods', $data);
- }
- # 配置商品
- public function action_commit_api()
- {
- $goods = Dever::input('goods');
- if (!$goods) {
- Dever::alert('请传入商品');
- }
- $role = Dever::input('role');
- $goods = Dever::json_decode($goods);
- $id = Dever::input('id');
- $col = $role . '_id';
- $table_goods = 'scm_role/'.$role.'_goods';
- $table_goods_sku = 'scm_role/'.$role.'_goods_sku';
- $info = Dever::db('scm_role/' . $role)->one($id);
- $where['option_' . $col] = $id;
- $where['set_state'] = 2;
- Dever::db($table_goods)->updates($where);
- Dever::db($table_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;
- }
- $w = array();
- $w['goods_id'] = $goods_id;
- $w[$col] = $id;
- $w['sku_id'] = $sku_id;
- if ($v['del'] == 2) {
- $sku_info = Dever::db($table_goods_sku)->one($w);
- if ($sku_info) {
- Dever::db($table_goods_sku)->update(array('where_id' => $sku_info['id'], 'state' => 2));
- }
- unset($w['sku_id']);
- $t = $w;
- $t['state'] = 1;
- $total = Dever::db($table_goods_sku)->total($t);
- if ($total <= 0) {
- $info = Dever::db($table_goods)->one($w);
- if ($info) {
- Dever::db($table_goods)->update(array('where_id' => $info['id'], 'state' => 2));
- }
- }
- } else {
- $goods_info = Dever::db('scm_product/info')->one($goods_id);
- $info = Dever::db($table_goods)->one($w);
- $u = $w;
- if (isset($v['min'])) {
- $u['min'] = $v['min'];
- }
- if (isset($v['cost_price'])) {
- $u['cost_price'] = $v['cost_price'];
- }
-
- if (!$info) {
- Dever::db($table_goods)->insert($u);
- } else {
- $u['where_id'] = $info['id'];
- $u['state'] = 1;
- Dever::db($table_goods)->update($u);
- }
- $u['sku_id'] = $w['sku_id'] = $sku_id;
- $info = Dever::db($table_goods_sku)->one($w);
- if (!$info) {
- Dever::db($table_goods_sku)->insert($u);
- } else {
- $u['where_id'] = $info['id'];
- $u['state'] = 1;
- Dever::db($table_goods_sku)->update($u);
- }
- }
- }
- return 'refer';
- }
- }
|