Set.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. namespace Scm_product\Lib;
  3. use Dever;
  4. class Set
  5. {
  6. # 获取商品列表
  7. public function goods_api()
  8. {
  9. $id = Dever::input('id', 1);
  10. $project = Dever::input('project');
  11. $table = Dever::input('table');
  12. $price_id = Dever::input('price_id', -1);
  13. $type = Dever::input('type', 1);
  14. $source = '';
  15. $table = 'scm_'.$project . '/' . $table;
  16. if ($type == 2) {
  17. $source = $table;
  18. $table = '';
  19. }
  20. $goods_category = Dever::input('goods_category');
  21. $where[$project . '_id'] = $id;
  22. return Dever::outDiy(Dever::load('scm_product/lib/info')->getSetList($table, $where, $goods_category, 'goods_id', array(), $price_id, $source));
  23. }
  24. # 配置商品
  25. public function home_api()
  26. {
  27. $data = array();
  28. $data['id'] = Dever::input('id', 1);
  29. $data['project'] = Dever::input('project');
  30. $data['info'] = Dever::input('info');
  31. $data['table'] = Dever::input('table');
  32. $info = Dever::db('scm_' . $data['project'] . '/' . $data['info'])->find($data['id']);
  33. $data['info'] = $info;
  34. $data['host'] = Dever::url('lib/set.home', 'scm_product');
  35. $uri = 'lib/set.goods?id=' . $data['id'] . '&project=' . $data['project'] . '&table=' . $data['table'];
  36. if (isset($info['category'])) {
  37. $uri .= '&goods_category=' . $info['category'];
  38. }
  39. if (isset($info['price_id'])) {
  40. $uri .= '&price_id=' . $info['price_id'];
  41. }
  42. $data['url'] = Dever::url($uri, 'scm_product');
  43. $data['submit'] = Dever::url('lib/set.action_commit?json=1', 'scm_product');
  44. return Dever::render('set_' . $data['project'] . '_goods', $data);
  45. }
  46. # 配置商品
  47. public function action_commit_api()
  48. {
  49. $goods = Dever::input('goods');
  50. if (!$goods) {
  51. Dever::alert('请传入商品');
  52. }
  53. $project = Dever::input('project');
  54. $table = Dever::input('table');
  55. $goods = Dever::json_decode($goods);
  56. $id = Dever::input('id');
  57. $col = $project . '_id';
  58. $table_goods = 'scm_' . $project . '/' . $table;
  59. $info = Dever::db('scm_' . $project . '/info')->one($id);
  60. $where['option_' . $col] = $id;
  61. $where['set_state'] = 2;
  62. Dever::db($table_goods)->updates($where);
  63. foreach ($goods as $k => $v) {
  64. $temp = explode('-', $k);
  65. $goods_id = $temp[0];
  66. if (isset($temp[1])) {
  67. $sku_id = $temp[1];
  68. } else {
  69. $sku_id = -1;
  70. }
  71. if ($v['num'] < 0) {
  72. continue;
  73. }
  74. $w = array();
  75. $w['goods_id'] = $goods_id;
  76. $w[$col] = $id;
  77. $w['sku_id'] = $sku_id;
  78. if ($v['del'] == 2) {
  79. $info = Dever::db($table_goods)->one($w);
  80. if ($info) {
  81. Dever::db($table_goods)->update(array('where_id' => $info['id'], 'state' => 2));
  82. }
  83. } else {
  84. $goods_info = Dever::db('scm_product/info')->one($goods_id);
  85. $info = Dever::db($table_goods)->one($w);
  86. if (isset($v['sell_min'])) {
  87. $w['sell_min'] = $v['sell_min'];
  88. }
  89. if (isset($v['buy_min'])) {
  90. $w['buy_min'] = $v['buy_min'];
  91. }
  92. if (isset($v['cost_price'])) {
  93. $w['cost_price'] = $v['cost_price'];
  94. }
  95. if (!$info) {
  96. Dever::db($table_goods)->insert($w);
  97. } else {
  98. $w['where_id'] = $info['id'];
  99. $w['state'] = 1;
  100. Dever::db($table_goods)->update($w);
  101. }
  102. }
  103. }
  104. return 'refer';
  105. }
  106. }