Seller.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. namespace Scm_role\Lib;
  3. use Dever;
  4. class Seller
  5. {
  6. # 获取商品列表
  7. public function getGoods($seller_id)
  8. {
  9. $where['seller_id'] = $seller_id;
  10. $where['sell_type'] = 1;
  11. $data = Dever::db('scm_role/seller_goods')->getDataPage($where);
  12. if ($data) {
  13. foreach ($data as $k => $v) {
  14. $v['id'] = $v['goods_id'];
  15. $data[$k] = Dever::load('scm_product/lib/info')->getInfo($v);
  16. }
  17. }
  18. return $data;
  19. }
  20. # 采购商品
  21. public function buyGoods_api()
  22. {
  23. $data = array();
  24. $data['seller_id'] = Dever::input('id', 1);
  25. $info = Dever::db('scm_role/seller')->find($data['seller_id']);
  26. $data['info'] = $info;
  27. $goods_category = $info['category'];
  28. $data['host'] = Dever::url('lib/seller.buyGoods', 'scm_role');
  29. $data['url'] = Dever::url('lib/seller.goods?seller_id=' . $data['seller_id'] . '&goods_category=' . $goods_category . '&price_id=' . $info['price_id'] . '&type=2', 'scm_role');
  30. $data['submit'] = Dever::url('lib/seller.buyGoods_action_commit?json=1', 'scm_role');
  31. return Dever::render('buy_seller_goods', $data);
  32. }
  33. # 采购商品
  34. public function buyGoods_action_commit_api()
  35. {
  36. $goods = Dever::input('goods');
  37. if (!$goods) {
  38. Dever::alert('请传入商品');
  39. }
  40. $goods = Dever::json_decode($goods);
  41. $seller_id = Dever::input('seller_id');
  42. $seller = Dever::db('scm_role/seller')->one($seller_id);
  43. $where['option_seller_id'] = $seller_id;
  44. $where['set_state'] = 2;
  45. Dever::db('scm_role/seller_goods')->updates($where);
  46. Dever::db('scm_role/seller_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['seller_id'] = $seller_id;
  62. $w['sku_id'] = $sku_id;
  63. $sku_info = Dever::db('scm_role/seller_goods_sku')->one($w);
  64. if ($sku_info) {
  65. Dever::db('scm_role/seller_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('scm_role/seller_goods_sku')->total($t);
  71. if ($total <= 0) {
  72. $info = Dever::db('scm_role/seller_goods')->one($w);
  73. if ($info) {
  74. Dever::db('scm_role/seller_goods')->update(array('where_id' => $info['id'], 'state' => 2));
  75. }
  76. }
  77. } else {
  78. $goods_info = Dever::db('scm_product/info')->one($goods_id);
  79. $w = array();
  80. $w['goods_id'] = $goods_id;
  81. $w['seller_id'] = $seller_id;
  82. $info = Dever::db('scm_role/seller_goods')->one($w);
  83. $w['in_num'] = $v['num'];
  84. $w['min'] = $v['min'];
  85. if (!$info) {
  86. Dever::db('scm_role/seller_goods')->insert($w);
  87. } else {
  88. $w['in_num'] += $info['in_num'];
  89. $w['where_id'] = $info['id'];
  90. $w['state'] = 1;
  91. Dever::db('scm_role/seller_goods')->update($w);
  92. }
  93. $w = array();
  94. $w['goods_id'] = $goods_id;
  95. $w['seller_id'] = $seller_id;
  96. $w['sku_id'] = $sku_id;
  97. $info = Dever::db('scm_role/seller_goods_sku')->one($w);
  98. $w['in_num'] = $v['num'];
  99. $w['min'] = $v['min'];
  100. if (!$info) {
  101. Dever::db('scm_role/seller_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('scm_role/seller_goods_sku')->update($w);
  107. }
  108. }
  109. }
  110. return 'refer';
  111. }
  112. }