Set.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <?php
  2. namespace Shop\Lib;
  3. use Dever;
  4. # 批量设置商品
  5. class Set
  6. {
  7. # 导出订单
  8. public function __construct()
  9. {
  10. Dever::load('manage/auth.init');
  11. }
  12. # 获取门店
  13. public function search_api()
  14. {
  15. return Dever::search('shop/info');
  16. }
  17. # 获取商品列表
  18. public function goods_api()
  19. {
  20. $shop_id = Dever::input('shop_id', 1);
  21. return Dever::outDiy(Dever::load('goods/lib/set')->getGoodsList($shop_id, 'shop_id', 'shop/goods_sku'));
  22. }
  23. # 设置生产能力
  24. public function home_api()
  25. {
  26. $data = array();
  27. $data['shop_id'] = Dever::input('id', 1);
  28. $data['host'] = Dever::url('lib/set.home', 'shop');
  29. $data['url'] = Dever::url('lib/set.goods?shop_id=' . $data['shop_id'], 'shop');
  30. $data['search'] = Dever::url('lib/set.search?yes='.$data['shop_id'].'&json=1', 'shop');
  31. $data['submit'] = Dever::url('lib/set.action_commit?json=1', 'shop');
  32. return Dever::render('setGoods', $data);
  33. }
  34. # 设置生产能力
  35. public function action_commit_api()
  36. {
  37. $goods = Dever::input('goods');
  38. if (!$goods) {
  39. Dever::alert('请传入商品');
  40. }
  41. $goods = Dever::json_decode($goods);
  42. $shop_id = Dever::input('shop_id');
  43. $shop = Dever::db('shop/info')->one($shop_id);
  44. $where['option_shop_id'] = $shop_id;
  45. $where['set_state'] = 2;
  46. Dever::db('shop/goods')->updates($where);
  47. Dever::db('shop/goods_sku')->updates($where);
  48. foreach ($goods as $k => $v) {
  49. $temp = explode('-', $k);
  50. $goods_id = $temp[0];
  51. if (isset($temp[1])) {
  52. $sku_id = $temp[1];
  53. } else {
  54. $sku_id = -1;
  55. }
  56. if ($v['num'] < 0) {
  57. continue;
  58. }
  59. if ($v['del'] == 2) {
  60. $w = array();
  61. $w['goods_id'] = $goods_id;
  62. $w['shop_id'] = $shop_id;
  63. $w['sku_id'] = $sku_id;
  64. $sku_info = Dever::db('shop/goods_sku')->one($w);
  65. if ($sku_info) {
  66. Dever::db('shop/goods_sku')->update(array('where_id' => $sku_info['id'], 'state' => 2));
  67. }
  68. unset($w['sku_id']);
  69. $t = $w;
  70. $t['state'] = 1;
  71. $total = Dever::db('shop/goods_sku')->total($t);
  72. if ($total <= 0) {
  73. $info = Dever::db('shop/goods')->one($w);
  74. if ($info) {
  75. Dever::db('shop/goods')->update(array('where_id' => $info['id'], 'state' => 2));
  76. }
  77. }
  78. } else {
  79. $goods_info = Dever::db('goods/info')->one($goods_id);
  80. $w = array();
  81. $w['goods_id'] = $goods_id;
  82. $w['shop_id'] = $shop_id;
  83. $info = Dever::db('shop/goods')->one($w);
  84. $w['status'] = $goods_info['status'];
  85. $w['total_num'] = $v['num'];
  86. $w['min'] = $v['min'];
  87. if (!$info) {
  88. Dever::db('shop/goods')->insert($w);
  89. } else {
  90. $w['total_num'] += $info['total_num'];
  91. $w['where_id'] = $info['id'];
  92. $w['state'] = 1;
  93. Dever::db('shop/goods')->update($w);
  94. }
  95. $w = array();
  96. $w['goods_id'] = $goods_id;
  97. $w['shop_id'] = $shop_id;
  98. $w['sku_id'] = $sku_id;
  99. $info = Dever::db('shop/goods_sku')->one($w);
  100. $w['status'] = $goods_info['status'];
  101. $w['total_num'] = $v['num'];
  102. $w['min'] = $v['min'];
  103. $w['area'] = $shop['area'];
  104. $w['price_id'] = $v['price_template_id'];
  105. if (!$info) {
  106. Dever::db('shop/goods_sku')->insert($w);
  107. } else {
  108. $w['total_num'] += $info['total_num'];
  109. $w['where_id'] = $info['id'];
  110. $w['state'] = 1;
  111. Dever::db('shop/goods_sku')->update($w);
  112. }
  113. }
  114. }
  115. return 'refer';
  116. return Dever::url('project/database/list&project=shop&&table=info&menu=shop&search_option_state=1', 'manage');
  117. }
  118. # 获取工厂列表
  119. public function getFactory_api()
  120. {
  121. $shop_id = Dever::input('shop_id', 1);
  122. $shop_factory = Dever::db('shop/factory')->getAll(array('shop_id' => $shop_id));
  123. $factory = Dever::db('factory/info')->select(array('status' => 1));
  124. $result = array();
  125. foreach ($factory as $k => $v) {
  126. $key = $v['area'];
  127. $area = Dever::load('area/api')->string($key, '', true, '');
  128. if (!isset($result[$key])) {
  129. $result[$key] = array();
  130. $result[$key]['id'] = $v['id'];
  131. $result[$key]['name'] = $area;
  132. $result[$key]['select'] = 2;
  133. $result[$key]['end'] = false;
  134. $result[$key]['children'] = array();
  135. }
  136. $data = array();
  137. $data['id'] = $v['id'];
  138. $data['name'] = $v['name'];
  139. $data['area'] = $area;
  140. $data['select'] = 2;
  141. $data['end'] = true;
  142. if (isset($shop_factory[$v['id']]) && $shop_factory[$v['id']]) {
  143. $data['select'] = 1;
  144. }
  145. $result[$key]['children'][] = $data;
  146. }
  147. $result = array_values($result);
  148. return Dever::outDiy($result);
  149. }
  150. # 分配工厂
  151. public function factory_api()
  152. {
  153. $data = array();
  154. $data['shop_id'] = Dever::input('id', 1);
  155. $data['host'] = Dever::url('lib/set.factory', 'shop');
  156. $data['url'] = Dever::url('lib/set.getFactory?shop_id=' . $data['shop_id'], 'shop');
  157. $data['search'] = Dever::url('lib/set.search?yes='.$data['shop_id'].'&json=1', 'shop');
  158. $data['submit'] = Dever::url('lib/set.source_commit?json=1&type=factory', 'shop');
  159. return Dever::render('setFactory', $data);
  160. }
  161. # 获取仓库列表
  162. public function getStore_api()
  163. {
  164. $shop_id = Dever::input('shop_id', 1);
  165. $shop_store = Dever::db('shop/store')->getAll(array('shop_id' => $shop_id));
  166. $store = Dever::db('store/info')->select(array('status' => 1));
  167. $result = array();
  168. foreach ($store as $k => $v) {
  169. $key = $v['area'];
  170. $area = Dever::load('area/api')->string($key, '', true, '');
  171. if (!isset($result[$key])) {
  172. $result[$key] = array();
  173. $result[$key]['id'] = $v['id'];
  174. $result[$key]['name'] = $area;
  175. $result[$key]['select'] = 2;
  176. $result[$key]['end'] = false;
  177. $result[$key]['children'] = array();
  178. }
  179. $data = array();
  180. $data['id'] = $v['id'];
  181. $data['name'] = $v['name'];
  182. $data['area'] = $area;
  183. $data['select'] = 2;
  184. $data['end'] = true;
  185. if (isset($shop_store[$v['id']]) && $shop_store[$v['id']]) {
  186. $data['select'] = 1;
  187. }
  188. $result[$key]['children'][] = $data;
  189. }
  190. $result = array_values($result);
  191. return Dever::outDiy($result);
  192. }
  193. # 分配仓库
  194. public function store_api()
  195. {
  196. $data = array();
  197. $data['shop_id'] = Dever::input('id', 1);
  198. $data['host'] = Dever::url('lib/set.store', 'shop');
  199. $data['url'] = Dever::url('lib/set.getStore?shop_id=' . $data['shop_id'], 'shop');
  200. $data['search'] = Dever::url('lib/set.search?yes='.$data['shop_id'].'&json=1', 'shop');
  201. $data['submit'] = Dever::url('lib/set.source_commit?json=1&type=store', 'shop');
  202. return Dever::render('setStore', $data);
  203. }
  204. public function source_commit_api()
  205. {
  206. $value = Dever::input('value');
  207. if (!$value) {
  208. Dever::alert('未选择');
  209. }
  210. $value = Dever::json_decode($value);
  211. $shop_id = Dever::input('shop_id');
  212. $type = Dever::input('type');
  213. $col = $type . '_id';
  214. $table = 'shop/' . $type;
  215. $where['option_shop_id'] = $shop_id;
  216. $where['set_state'] = 2;
  217. Dever::db($table)->updates($where);
  218. foreach ($value as $k => $v) {
  219. $w = array();
  220. $w[$col] = $v['id'];
  221. $w['shop_id'] = $shop_id;
  222. $info = Dever::db($table)->one($w);
  223. if (!$info) {
  224. Dever::db($table)->insert($w);
  225. } else {
  226. $w['where_id'] = $info['id'];
  227. $w['state'] = 1;
  228. Dever::db($table)->update($w);
  229. }
  230. }
  231. return 'refer';
  232. return Dever::url('project/database/list&project=shop&&table=info&menu=shop&search_option_state=1', 'manage');
  233. }
  234. }