Set.php 4.4 KB

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