Set.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. namespace Store\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('store/info');
  16. }
  17. # 获取商品列表
  18. public function goods_api()
  19. {
  20. $store_id = Dever::input('store_id', 1);
  21. return Dever::outDiy(Dever::load('goods/lib/set')->getGoodsList($store_id, 'store_id', 'store/goods_sku'));
  22. }
  23. # 设置生产能力
  24. public function home_api()
  25. {
  26. $data = array();
  27. $data['store_id'] = Dever::input('id', 1);
  28. $data['host'] = Dever::url('lib/set.home', 'store');
  29. $data['url'] = Dever::url('lib/set.goods?store_id=' . $data['store_id'], 'store');
  30. $data['search'] = Dever::url('lib/set.search?yes='.$data['store_id'].'&json=1', 'store');
  31. $data['submit'] = Dever::url('lib/set.action_commit?json=1', 'store');
  32. return Dever::render('setGoodsNum', $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. $store_id = Dever::input('store_id');
  43. $where['option_store_id'] = $store_id;
  44. $where['set_state'] = 2;
  45. Dever::db('store/goods')->updates($where);
  46. Dever::db('store/goods_sku')->updates($where);
  47. foreach ($goods as $k => $v) {
  48. $temp = explode('-', $k);
  49. $goods_id = $temp[0];
  50. if (isset($temp[1])) {
  51. $sku_id = $temp[1];
  52. } else {
  53. $sku_id = -1;
  54. }
  55. if ($v['num'] < 0) {
  56. continue;
  57. }
  58. if ($v['del'] == 2) {
  59. $w = array();
  60. $w['goods_id'] = $goods_id;
  61. $w['store_id'] = $store_id;
  62. $w['sku_id'] = $sku_id;
  63. $sku_info = Dever::db('store/goods_sku')->one($w);
  64. if ($sku_info) {
  65. Dever::db('store/goods_sku')->update(array('where_id' => $sku_info['id'], 'state' => 2));
  66. }
  67. unset($w['sku_id']);
  68. $t = $w;
  69. $t['state'] = 1;
  70. $total = Dever::db('store/goods_sku')->total($t);
  71. if ($total <= 0) {
  72. $info = Dever::db('store/goods')->one($w);
  73. if ($info) {
  74. Dever::db('store/goods')->update(array('where_id' => $info['id'], 'state' => 2));
  75. }
  76. }
  77. } else {
  78. $goods_info = Dever::db('goods/info')->one($goods_id);
  79. $w = array();
  80. $w['goods_id'] = $goods_id;
  81. $w['store_id'] = $store_id;
  82. $info = Dever::db('store/goods')->one($w);
  83. $w['status'] = $goods_info['status'];
  84. $w['total_num'] = $v['num'];
  85. if (!$info) {
  86. Dever::db('store/goods')->insert($w);
  87. } else {
  88. $w['total_num'] += $info['total_num'];
  89. $w['where_id'] = $info['id'];
  90. $w['state'] = 1;
  91. Dever::db('store/goods')->update($w);
  92. }
  93. $w = array();
  94. $w['goods_id'] = $goods_id;
  95. $w['store_id'] = $store_id;
  96. $w['sku_id'] = $sku_id;
  97. $info = Dever::db('store/goods_sku')->one($w);
  98. $w['status'] = $goods_info['status'];
  99. $w['total_num'] = $v['num'];
  100. if (isset($v['price_template_id']) && $v['price_template_id']) {
  101. $w['price_id'] = $v['price_template_id'];
  102. }
  103. if (!$info) {
  104. Dever::db('store/goods_sku')->insert($w);
  105. } else {
  106. $w['total_num'] += $info['total_num'];
  107. $w['where_id'] = $info['id'];
  108. $w['state'] = 1;
  109. Dever::db('store/goods_sku')->update($w);
  110. }
  111. }
  112. }
  113. return Dever::url('project/database/list&project=store&&table=info&menu=store&search_option_state=1', 'manage');
  114. }
  115. }