Supplier.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. namespace Role\Lib;
  3. use Dever;
  4. class Supplier
  5. {
  6. public function __construct()
  7. {
  8. Dever::load('manage/auth.init');
  9. }
  10. # 获取门店
  11. public function search_api()
  12. {
  13. return Dever::search('product/category', array(), 'getTop');
  14. }
  15. # 获取商品列表
  16. public function goods_api()
  17. {
  18. $supplier_id = Dever::input('supplier_id', 1);
  19. $goods_category = Dever::input('goods_category');
  20. $where['supplier_id'] = $supplier_id;
  21. return Dever::outDiy(Dever::load('product/lib/info')->getSetList('role/supplier_goods_sku', $where, $goods_category));
  22. }
  23. # 配置商品
  24. public function setGoods_api()
  25. {
  26. $data = array();
  27. $data['supplier_id'] = Dever::input('id', 1);
  28. $info = Dever::db('role/supplier')->find($data['supplier_id']);
  29. $data['info'] = $info;
  30. $goods_category = $info['category'];
  31. $data['host'] = Dever::url('lib/supplier.setGoods', 'role');
  32. $data['url'] = Dever::url('lib/supplier.goods?supplier_id=' . $data['supplier_id'] . '&goods_category=' . $goods_category, 'role');
  33. //$data['search'] = Dever::url('lib/supplier.search?yes='.$data['supplier_id'].'&json=1', 'role');
  34. $data['submit'] = Dever::url('lib/supplier.setGoods_action_commit?json=1', 'role');
  35. return Dever::render('set_supplier_goods', $data);
  36. }
  37. # 配置商品
  38. public function setGoods_action_commit_api()
  39. {
  40. $goods = Dever::input('goods');
  41. if (!$goods) {
  42. Dever::alert('请传入商品');
  43. }
  44. $goods = Dever::json_decode($goods);
  45. $supplier_id = Dever::input('supplier_id');
  46. $supplier = Dever::db('role/supplier')->one($supplier_id);
  47. $where['option_supplier_id'] = $supplier_id;
  48. $where['set_state'] = 2;
  49. Dever::db('role/supplier_goods')->updates($where);
  50. Dever::db('role/supplier_goods_sku')->updates($where);
  51. foreach ($goods as $k => $v) {
  52. $temp = explode('-', $k);
  53. $goods_id = $temp[0];
  54. if (isset($temp[1])) {
  55. $sku_id = $temp[1];
  56. } else {
  57. $sku_id = -1;
  58. }
  59. if ($v['num'] < 0) {
  60. continue;
  61. }
  62. if ($v['del'] == 2) {
  63. $w = array();
  64. $w['goods_id'] = $goods_id;
  65. $w['supplier_id'] = $supplier_id;
  66. $w['sku_id'] = $sku_id;
  67. $sku_info = Dever::db('role/supplier_goods_sku')->one($w);
  68. if ($sku_info) {
  69. Dever::db('role/supplier_goods_sku')->update(array('where_id' => $sku_info['id'], 'state' => 2));
  70. }
  71. unset($w['sku_id']);
  72. $t = $w;
  73. $t['state'] = 1;
  74. $total = Dever::db('role/supplier_goods_sku')->total($t);
  75. if ($total <= 0) {
  76. $info = Dever::db('role/supplier_goods')->one($w);
  77. if ($info) {
  78. Dever::db('role/supplier_goods')->update(array('where_id' => $info['id'], 'state' => 2));
  79. }
  80. }
  81. } else {
  82. $goods_info = Dever::db('product/info')->one($goods_id);
  83. $w = array();
  84. $w['goods_id'] = $goods_id;
  85. $w['supplier_id'] = $supplier_id;
  86. $info = Dever::db('role/supplier_goods')->one($w);
  87. if (!$info) {
  88. Dever::db('role/supplier_goods')->insert($w);
  89. } else {
  90. $w['where_id'] = $info['id'];
  91. $w['state'] = 1;
  92. Dever::db('role/supplier_goods')->update($w);
  93. }
  94. $w = array();
  95. $w['goods_id'] = $goods_id;
  96. $w['supplier_id'] = $supplier_id;
  97. $w['sku_id'] = $sku_id;
  98. $info = Dever::db('role/supplier_goods_sku')->one($w);
  99. $w['in_num'] = $v['num'];
  100. if (!$info) {
  101. Dever::db('role/supplier_goods_sku')->insert($w);
  102. } else {
  103. $w['in_num'] += $info['in_num'];
  104. $w['where_id'] = $info['id'];
  105. $w['state'] = 1;
  106. Dever::db('role/supplier_goods_sku')->update($w);
  107. }
  108. }
  109. }
  110. return 'refer';
  111. }
  112. }