123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?php
- namespace Agent\Lib;
- use Dever;
- # 批量设置商品
- class Order_set
- {
- public function __construct()
- {
- Dever::load('manage/auth.init');
- }
- # 获取商品列表
- public function goods_api()
- {
- $id = Dever::input('role_id', 1);
- return Dever::load('agent/lib/set')->getData($id);
- }
- # 设置商品
- public function home_api()
- {
- $data = array();
- $data['link'] = Dever::decode(Dever::input('refer'));
- $data['total'] = Dever::input('total', 1);
- $data['order_id'] = Dever::input('order_id');
- $data['type'] = Dever::input('type');
- $data['role_id'] = Dever::input('role_id', 1);
- $data['host'] = Dever::url('lib/order_set.home?type='.$data['type'].'&id=' . $data['role_id'] . '&order_id=' . $data['order_id'], 'agent');
- $data['url'] = Dever::url('lib/order_set.goods?type='.$data['type'].'&total='.$data['total'].'&role_id=' . $data['role_id'] . '&order_id=' . $data['order_id'], 'agent');
- $data['submit'] = Dever::url('lib/order_set.action_commit?json=1', 'agent');
- return Dever::render('setOrderGoods', $data);
- }
- # 设置生产能力
- public function action_commit_api()
- {
- $goods = Dever::input('goods');
- if (!$goods) {
- Dever::alert('请传入商品');
- }
- $goods = Dever::json_decode($goods);
- $order_id = Dever::input('order_id');
- $role_id = Dever::input('role_id');
- $where['option_order_id'] = $order_id;
- $where['set_state'] = 2;
- Dever::db('agent/order_goods')->updates($where);
- foreach ($goods as $k => $v) {
- $type = 1;
- $type_id = $k;
- $sku_id = -1;
- if (strstr($k, '_')) {
- $temp = explode('_', $k);
- $type_id = $temp[0];
- $type = $temp[1];
- } elseif (strstr($k, '-')) {
- $temp = explode('-', $k);
- $type_id = $temp[0];
- $sku_id = $temp[1];
- }
-
- if ($v['total'] < 0) {
- continue;
- }
- $w = array();
- $w['type'] = $type;
- $w['type_id'] = $type_id;
- $w['sku_id'] = $sku_id;
- $w['order_id'] = $order_id;
-
- $info = Dever::db('agent/order_goods')->one($w);
- if ($v['del'] == 2 || $v['total'] <= 0) {
- if ($info) {
- Dever::db('agent/order_goods')->update(array('where_id' => $info['id'], 'state' => 2));
- }
- } else {
- $w['num'] = $v['total'];
-
- if (!$info) {
- Dever::db('agent/order_goods')->insert($w);
- } else {
- $w['where_id'] = $info['id'];
- $w['state'] = 1;
- Dever::db('agent/order_goods')->update($w);
- }
- /*
- $wp = array();
- $wp['order_id'] = $order_id;
- $wp['status'] = 3;
- $process = Dever::db('agent/order_process')->find($wp);
- if ($process) {
- $process['type'] = explode(',', $process['type']);
- $wp['audit'] = 1;
- $wp['type'] = '1,2';
- Dever::db('agent/order_process')->insert($wp);
- } else {
- $wp['audit'] = 1;
- $wp['type'] = '1,2';
- Dever::db('agent/order_process')->insert($wp);
- }
- */
- }
- }
- $link = Dever::input('link');
- if ($link) {
- return $link;
- }
- return Dever::url('project/database/list&table=order_process&project=agent&order_id='.$order_id.'&page_type=1', 'manage');
- }
- }
|