Order.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. namespace Scm_role\Lib;
  3. use Dever;
  4. class Order
  5. {
  6. public function search_api()
  7. {
  8. $role = Dever::input('role');
  9. $where = array();
  10. if ($role == 'servicer_store') {
  11. $servicer = Dever::db('scm_role/servicer_store')->find(Dever::input('yes'));
  12. $where['servicer_id'] = $servicer['servicer_id'];
  13. }
  14. return Dever::search('scm_role/' . $role, $where);
  15. }
  16. # 获取商品列表
  17. public function goods_api()
  18. {
  19. $id = Dever::input('id', 1);
  20. $role = Dever::input('role');
  21. $price_id = Dever::input('price_id', -1);
  22. $type = Dever::input('type', 'in');
  23. $source = '';
  24. $table = '';
  25. $goods_category = Dever::input('goods_category');
  26. $where[$role . '_id'] = $id;
  27. return Dever::outDiy(Dever::load('scm_product/lib/info')->getSetList($table, $where, $goods_category, 'goods_id', array(), $price_id, $source));
  28. }
  29. # 入库下单
  30. public function home_api()
  31. {
  32. $data = array();
  33. $data['id'] = Dever::input('id', 1);
  34. $data['role'] = Dever::input('role');
  35. $data['type'] = Dever::input('type');
  36. $info_table = $data['role'];
  37. if (strstr($data['role'], '_')) {
  38. $temp = explode('_', $data['role']);
  39. $info_table = $temp[0];
  40. }
  41. $info = Dever::db('scm_role/' . $info_table)->find($data['id']);
  42. $data['info'] = $info;
  43. $data['host'] = Dever::url('lib/order.home', 'scm_role');
  44. $uri = 'lib/order.goods?id=' . $data['id'] . '&role=' . $data['role'];
  45. # 选择上游
  46. if ($data['role'] == 'seller') {
  47. $data['name'] = '销售商';
  48. $data['source'] = Dever::db('scm_role/supplier')->select();
  49. } elseif ($data['role'] == 'servicer_store') {
  50. $data['name'] = '仓库';
  51. $servicer = Dever::db('scm_role/servicer_store')->find($data['id']);
  52. $data['source'] = Dever::db('scm_role/servicer_supplier')->getData(array('servicer_id' => $servicer['servicer_id']));
  53. }
  54. $data['source'] = Dever::json_encode($data['source']);
  55. if ($data['type'] == 'in') {
  56. $data['type_name'] = '入库';
  57. $data['type_config'] = array(1,2);
  58. } else {
  59. $data['type_name'] = '出库';
  60. }
  61. $data['search'] = Dever::url('lib/order.search?yes='.$data['id'].'&role=' . $data['role'] . '&json=1', 'scm_role');
  62. if (isset($info['category'])) {
  63. $uri .= '&goods_category=' . $info['category'];
  64. }
  65. $data['url'] = Dever::url($uri, 'scm_role');
  66. $data['submit'] = Dever::url('lib/order.action_commit?json=1', 'scm_role');
  67. return Dever::render('order_' . $data['role'], $data);
  68. }
  69. # 入库下单
  70. public function action_commit_api()
  71. {
  72. $goods = Dever::input('goods');
  73. if (!$goods) {
  74. Dever::alert('请传入商品');
  75. }
  76. $role = Dever::input('role');
  77. $goods = Dever::json_decode($goods);
  78. $id = Dever::input('id');
  79. $col = $role . '_id';
  80. $table_goods = 'scm_role/'.$role.'_goods';
  81. $table_goods_sku = 'scm_role/'.$role.'_goods_sku';
  82. $info = Dever::db('scm_role/' . $role)->one($id);
  83. $where['option_' . $col] = $id;
  84. $where['set_state'] = 2;
  85. Dever::db($table_goods)->updates($where);
  86. Dever::db($table_goods_sku)->updates($where);
  87. foreach ($goods as $k => $v) {
  88. $temp = explode('-', $k);
  89. $goods_id = $temp[0];
  90. if (isset($temp[1])) {
  91. $sku_id = $temp[1];
  92. } else {
  93. $sku_id = -1;
  94. }
  95. if ($v['num'] < 0) {
  96. continue;
  97. }
  98. $w = array();
  99. $w['goods_id'] = $goods_id;
  100. $w[$col] = $id;
  101. $w['sku_id'] = $sku_id;
  102. if ($v['del'] == 2) {
  103. $sku_info = Dever::db($table_goods_sku)->one($w);
  104. if ($sku_info) {
  105. Dever::db($table_goods_sku)->update(array('where_id' => $sku_info['id'], 'state' => 2));
  106. }
  107. unset($w['sku_id']);
  108. $t = $w;
  109. $t['state'] = 1;
  110. $total = Dever::db($table_goods_sku)->total($t);
  111. if ($total <= 0) {
  112. $info = Dever::db($table_goods)->one($w);
  113. if ($info) {
  114. Dever::db($table_goods)->update(array('where_id' => $info['id'], 'state' => 2));
  115. }
  116. }
  117. } else {
  118. $goods_info = Dever::db('scm_product/info')->one($goods_id);
  119. $info = Dever::db($table_goods)->one($w);
  120. $u = $w;
  121. $u['in_num'] = $v['num'];
  122. if (!$info) {
  123. Dever::db($table_goods)->insert($u);
  124. } else {
  125. $u['where_id'] = $info['id'];
  126. $u['state'] = 1;
  127. Dever::db($table_goods)->update($u);
  128. }
  129. $u['sku_id'] = $w['sku_id'] = $sku_id;
  130. $info = Dever::db($table_goods_sku)->one($w);
  131. if (!$info) {
  132. Dever::db($table_goods_sku)->insert($u);
  133. } else {
  134. $u['where_id'] = $info['id'];
  135. $u['state'] = 1;
  136. Dever::db($table_goods_sku)->update($u);
  137. }
  138. }
  139. }
  140. return 'refer';
  141. }
  142. }