Set.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace Factory\Lib;
  3. use Dever;
  4. # 批量设置商品
  5. class Set
  6. {
  7. # 导出订单
  8. public function __construct()
  9. {
  10. Dever::load('manage/auth.init');
  11. }
  12. # 获取工厂
  13. public function search_api()
  14. {
  15. return Dever::search('factory/info');
  16. }
  17. # 获取商品列表
  18. public function goods_api()
  19. {
  20. $factory_id = Dever::input('factory_id', 1);
  21. return Dever::outDiy(Dever::load('goods/lib/set')->getGoodsList($factory_id, 'factory_id', 'factory/goods_sku'));
  22. }
  23. # 设置生产能力
  24. public function home_api()
  25. {
  26. $data = array();
  27. $data['factory_id'] = Dever::input('id', 1);
  28. $data['host'] = Dever::url('lib/set.home', 'factory');
  29. $data['url'] = Dever::url('lib/set.goods?factory_id=' . $data['factory_id'], 'factory');
  30. $data['search'] = Dever::url('lib/set.search?yes='.$data['factory_id'].'&json=1', 'factory');
  31. $data['submit'] = Dever::url('lib/set.action_commit?json=1', 'factory');
  32. return Dever::render('setGoods', $data);
  33. }
  34. # 设置生产能力
  35. public function action_commit_api()
  36. {
  37. $goods = Dever::input('goods');
  38. if (!$goods) {
  39. Dever::alert('请传入商品');
  40. }
  41. $goods = Dever::json_decode($goods);
  42. $factory_id = Dever::input('factory_id');
  43. $where['option_factory_id'] = $factory_id;
  44. $where['set_state'] = 2;
  45. Dever::db('factory/goods')->updates($where);
  46. Dever::db('factory/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. $goods_info = Dever::db('goods/info')->one($goods_id);
  56. $w = array();
  57. $w['goods_id'] = $goods_id;
  58. $w['factory_id'] = $factory_id;
  59. $info = Dever::db('factory/goods')->one($w);
  60. $w['status'] = $goods_info['status'];
  61. $w['p_price'] = $v['p_price'];
  62. if (!$info) {
  63. Dever::db('factory/goods')->insert($w);
  64. } else {
  65. $w['where_id'] = $info['id'];
  66. $w['state'] = 1;
  67. Dever::db('factory/goods')->update($w);
  68. }
  69. $w = array();
  70. $w['goods_id'] = $goods_id;
  71. $w['factory_id'] = $factory_id;
  72. $w['sku_id'] = $sku_id;
  73. $info = Dever::db('factory/goods_sku')->one($w);
  74. $w['status'] = $goods_info['status'];
  75. $w['p_price'] = $v['p_price'];
  76. if (!$info) {
  77. Dever::db('factory/goods_sku')->insert($w);
  78. } else {
  79. $w['where_id'] = $info['id'];
  80. $w['state'] = 1;
  81. Dever::db('factory/goods_sku')->update($w);
  82. }
  83. }
  84. return Dever::url('project/database/list&project=factory&&table=info&menu=factory&search_option_state=1', 'manage');
  85. }
  86. }