Order_set.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace Agent\Lib;
  3. use Dever;
  4. # 批量设置商品
  5. class Order_set
  6. {
  7. public function __construct()
  8. {
  9. Dever::load('manage/auth.init');
  10. }
  11. # 获取商品列表
  12. public function goods_api()
  13. {
  14. $id = Dever::input('role_id', 1);
  15. return Dever::load('agent/lib/set')->getData($id);
  16. }
  17. # 设置商品
  18. public function home_api()
  19. {
  20. $data = array();
  21. $data['link'] = Dever::decode(Dever::input('refer'));
  22. $data['total'] = Dever::input('total', 1);
  23. $data['order_id'] = Dever::input('order_id');
  24. $data['type'] = Dever::input('type');
  25. $data['role_id'] = Dever::input('role_id', 1);
  26. $data['host'] = Dever::url('lib/order_set.home?type='.$data['type'].'&id=' . $data['role_id'] . '&order_id=' . $data['order_id'], 'agent');
  27. $data['url'] = Dever::url('lib/order_set.goods?type='.$data['type'].'&total='.$data['total'].'&role_id=' . $data['role_id'] . '&order_id=' . $data['order_id'], 'agent');
  28. $data['submit'] = Dever::url('lib/order_set.action_commit?json=1', 'agent');
  29. return Dever::render('setOrderGoods', $data);
  30. }
  31. # 设置生产能力
  32. public function action_commit_api()
  33. {
  34. $goods = Dever::input('goods');
  35. if (!$goods) {
  36. Dever::alert('请传入商品');
  37. }
  38. $goods = Dever::json_decode($goods);
  39. $order_id = Dever::input('order_id');
  40. $role_id = Dever::input('role_id');
  41. $where['option_order_id'] = $order_id;
  42. $where['set_state'] = 2;
  43. Dever::db('agent/order_goods')->updates($where);
  44. foreach ($goods as $k => $v) {
  45. $type = 1;
  46. $type_id = $k;
  47. $sku_id = -1;
  48. if (strstr($k, '_')) {
  49. $temp = explode('_', $k);
  50. $type_id = $temp[0];
  51. $type = $temp[1];
  52. } elseif (strstr($k, '-')) {
  53. $temp = explode('-', $k);
  54. $type_id = $temp[0];
  55. $sku_id = $temp[1];
  56. }
  57. if ($v['total'] < 0) {
  58. continue;
  59. }
  60. $w = array();
  61. $w['type'] = $type;
  62. $w['type_id'] = $type_id;
  63. $w['sku_id'] = $sku_id;
  64. $w['order_id'] = $order_id;
  65. $info = Dever::db('agent/order_goods')->one($w);
  66. if ($v['del'] == 2 || $v['total'] <= 0) {
  67. if ($info) {
  68. Dever::db('agent/order_goods')->update(array('where_id' => $info['id'], 'state' => 2));
  69. }
  70. } else {
  71. $w['num'] = $v['total'];
  72. if (!$info) {
  73. Dever::db('agent/order_goods')->insert($w);
  74. } else {
  75. $w['where_id'] = $info['id'];
  76. $w['state'] = 1;
  77. Dever::db('agent/order_goods')->update($w);
  78. }
  79. /*
  80. $wp = array();
  81. $wp['order_id'] = $order_id;
  82. $wp['status'] = 3;
  83. $process = Dever::db('agent/order_process')->find($wp);
  84. if ($process) {
  85. $process['type'] = explode(',', $process['type']);
  86. $wp['audit'] = 1;
  87. $wp['type'] = '1,2';
  88. Dever::db('agent/order_process')->insert($wp);
  89. } else {
  90. $wp['audit'] = 1;
  91. $wp['type'] = '1,2';
  92. Dever::db('agent/order_process')->insert($wp);
  93. }
  94. */
  95. }
  96. }
  97. $link = Dever::input('link');
  98. if ($link) {
  99. return $link;
  100. }
  101. return Dever::url('project/database/list&table=order_process&project=agent&order_id='.$order_id.'&page_type=1', 'manage');
  102. }
  103. }