Price.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace Product\Lib;
  3. use Dever;
  4. class Price
  5. {
  6. public function __construct()
  7. {
  8. Dever::load('manage/auth.init');
  9. }
  10. # 获取商品列表
  11. public function goods_api()
  12. {
  13. $price_rule_id = Dever::input('price_rule_id', 1);
  14. $goods_category = Dever::input('goods_category');
  15. $where['price_rule_id'] = $price_rule_id;
  16. return Dever::outDiy(Dever::load('product/lib/info')->getSetList('product/price_rule_sku', $where, $goods_category));
  17. }
  18. # 配置商品
  19. public function setGoods_api()
  20. {
  21. $data = array();
  22. $data['price_rule_id'] = Dever::input('id', 1);
  23. $price = Dever::db('product/price_rule')->find($data['price_rule_id']);
  24. $goods_category = '';
  25. $data['type'] = 1;
  26. $data['sell_num'] = $data['sell_num'] = 0;
  27. if ($price) {
  28. $goods_category = $price['category'];
  29. $data['type'] = $price['type'];
  30. $data['sell_num'] = $price['sell_num'];
  31. $data['buy_num'] = $price['buy_num'];
  32. }
  33. $data['host'] = Dever::url('lib/price.setGoods', 'product');
  34. $data['url'] = Dever::url('lib/price.goods?price_rule_id=' . $data['price_rule_id'] . '&goods_category=' . $goods_category . '&price=' . $data['sell_num'] . '&buy_price=' . $data['buy_num'], 'product');
  35. $data['submit'] = Dever::url('lib/price.setGoods_action_commit?json=1', 'product');
  36. return Dever::render('set_price_goods', $data);
  37. }
  38. # 配置商品
  39. public function setGoods_action_commit_api()
  40. {
  41. $goods = Dever::input('goods');
  42. if (!$goods) {
  43. Dever::alert('请传入商品');
  44. }
  45. $goods = Dever::json_decode($goods);
  46. $price_rule_id = Dever::input('price_rule_id');
  47. $shop = Dever::db('product/price')->one($price_rule_id);
  48. $where['option_price_rule_id'] = $price_rule_id;
  49. $where['set_state'] = 2;
  50. Dever::db('product/price_rule_sku')->updates($where);
  51. foreach ($goods as $k => $v) {
  52. if ($v['del'] == 1) {
  53. $temp = explode('-', $k);
  54. $goods_id = $temp[0];
  55. $sku_id = -1;
  56. if (isset($temp[1])) {
  57. $sku_id = $temp[1];
  58. }
  59. $goods_info = Dever::db('product/info')->one($goods_id);
  60. $w = array();
  61. $w['goods_id'] = $goods_id;
  62. $w['sku_id'] = $sku_id;
  63. $w['price_rule_id'] = $price_rule_id;
  64. $sku_info = Dever::db('product/price_rule_sku')->one($w);
  65. $w['status'] = $goods_info['status'];
  66. if (isset($v['price']) && $v['price']) {
  67. $w['price'] = $v['price'];
  68. }
  69. if (isset($v['buy_price']) && $v['buy_price']) {
  70. $w['buy_price'] = $v['buy_price'];
  71. }
  72. if (!$sku_info) {
  73. Dever::db('product/price_rule_sku')->insert($w);
  74. } else {
  75. $w['where_id'] = $sku_info['id'];
  76. $w['state'] = 1;
  77. Dever::db('product/price_rule_sku')->update($w);
  78. }
  79. }
  80. }
  81. return 'refer';
  82. }
  83. }