Manage.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <?php
  2. namespace Scm_product\Lib;
  3. use Dever;
  4. class Manage
  5. {
  6. public function check($id,$name,$data)
  7. {
  8. //Dever::alert('reload');
  9. }
  10. /**
  11. * 更新信息
  12. *
  13. * @return mixed
  14. */
  15. public function updateInfo($id, $name, $data)
  16. {
  17. # 更新分类id
  18. $category = Dever::param('category', $data);
  19. if ($category) {
  20. if (is_array($category)) {
  21. $category_id = end($category);
  22. $top_category_id = $category[0];
  23. if (isset($category[1])) {
  24. $second_category_id = $category[1];
  25. } else {
  26. $second_category_id = $category[0];
  27. }
  28. } else {
  29. $category_id = $category;
  30. $top_category_id = $category;
  31. $second_category_id = $category;
  32. }
  33. $update['top_category_id'] = $top_category_id;
  34. $update['second_category_id'] = $second_category_id;
  35. $update['category_id'] = $category_id;
  36. }
  37. if (isset($update)) {
  38. $update['where_id'] = $id;
  39. Dever::db('scm_product/info')->update($update);
  40. }
  41. }
  42. public function updateCategory($id, $name, $data)
  43. {
  44. $info = Dever::param('category', $data);
  45. if ($info && $info != -1) {
  46. $update['top_category_id'] = $info[0];
  47. $num = count($info)+1;
  48. $update['level'] = $num;
  49. $parent = Dever::param('category_id', $data);
  50. $child = Dever::db('scm_product/category')->one(array('category_id' => $id));
  51. if (!$child) {
  52. $update['level'] = -1;
  53. }
  54. Dever::db('scm_product/category')->update(array('where_id' => $parent, 'level' => $num - 1));
  55. } else {
  56. $update['level'] = 1;
  57. $update['top_category_id'] = -1;
  58. }
  59. if (isset($update)) {
  60. $update['where_id'] = $id;
  61. Dever::db('scm_product/category')->update($update);
  62. }
  63. }
  64. /**
  65. * 更新属性信息
  66. *
  67. * @return mixed
  68. */
  69. public function updateAttr($id, $name, $data)
  70. {
  71. return;
  72. $is_sell = Dever::param('is_sell', $data);
  73. if ($is_sell > 1) {
  74. $update['type'] = 11;
  75. }
  76. if (isset($update)) {
  77. $update['where_id'] = $id;
  78. Dever::db('scm_product/category_attr')->update($update);
  79. }
  80. }
  81. public function searchProduct_api()
  82. {
  83. $keyword = Dever::input('keyword');
  84. $where = array();
  85. if ($keyword) {
  86. $where['name'] = $keyword;
  87. }
  88. $data = array();
  89. $cate = '';
  90. $supplier_id = Dever::input('supplier_id');
  91. if ($supplier_id) {
  92. $supplier_goods = Dever::db('scm_supplier/goods')->one(array('supplier_id' => $supplier_id));
  93. if ($supplier_goods) {
  94. $where['supplier_id'] = $supplier_id;
  95. $data = Dever::search('scm_supplier/goods_sku', $where);
  96. } else {
  97. $supplier = Dever::db('scm_supplier/info')->find($supplier_id);
  98. if ($supplier && $supplier['category']) {
  99. $cate = $supplier['category'];
  100. }
  101. }
  102. }
  103. $service_id = Dever::input('service_id');
  104. $servicer_store_id = Dever::input('servicer_store_id');
  105. if ($servicer_store_id) {
  106. $store_goods = Dever::db('scm_servicer/store_goods')->one(array('servicer_store_id' => $servicer_store_id));
  107. if ($store_goods) {
  108. $where['servicer_store_id'] = $servicer_store_id;
  109. $data = Dever::search('scm_servicer/store_goods_sku', $where);
  110. } else {
  111. # 没有库存
  112. return array();
  113. }
  114. }
  115. if (!$data) {
  116. $id = Dever::input('where_id');
  117. if ($id) {
  118. $where['id_no'] = $id;
  119. }
  120. if ($cate) {
  121. $where['cate'] = $cate;
  122. }
  123. $data = Dever::search('scm_product/info', $where);
  124. }
  125. if ($data) {
  126. $old = $data;
  127. $data = array();
  128. foreach ($old as $k => $v) {
  129. Dever::load('scm_product/lib/sku')->getList($v, $data);
  130. }
  131. }
  132. return $data;
  133. }
  134. public function getGoods($id, $table = 'scm_servicer/in_order_goods', $cash = true)
  135. {
  136. $result = array();
  137. $result['head'] = array('名称', '批次', '单价', '数量', '状态');
  138. if (!$cash) {
  139. unset($result['head'][1]);
  140. }
  141. $result['body'] = array();
  142. $data = Dever::db($table)->select(array('order_id' => $id));
  143. if ($data) {
  144. $status = Dever::db($table)->config['status'];
  145. foreach ($data as $k => $v) {
  146. $goods_info = Dever::load('scm_product/lib/info')->getBaseInfo($v['goods_id'], $v['sku_id']);
  147. $status_name = Dever::status($status, $v['status']);
  148. $result['body'][$k][] = $goods_info['aname'];
  149. $result['body'][$k][] = $v['batch'];
  150. $result['body'][$k][] = $v['cash'];
  151. $result['body'][$k][] = $v['num'];
  152. $result['body'][$k][] = $status_name;
  153. if (!$cash) {
  154. unset($result['body'][$k][1]);
  155. }
  156. }
  157. }
  158. $body[''] = array
  159. (
  160. 'type' => 'table',
  161. 'content' => $result,
  162. );
  163. if ($result['body']) {
  164. return Dever::show('', $body);
  165. } else {
  166. return '暂无';
  167. }
  168. }
  169. public function searchRole_api()
  170. {
  171. $in_type = Dever::input('in_type');
  172. $service_id = Dever::input('service_id');
  173. $servicer_store_id = Dever::input('servicer_store_id');
  174. if ($in_type == 2) {
  175. # 生成仓库入库单
  176. }
  177. }
  178. # 根据商品获取信息,后台入库出库单使用
  179. public function showInfo_api()
  180. {
  181. $goods = Dever::input('value');
  182. list($goods_id, $sku_id) = explode('-', $goods);
  183. $goods_info = Dever::load('scm_product/lib/info')->getBaseInfo($goods_id, $sku_id);
  184. $option = array();
  185. $result = array();
  186. $result['goods_id'] = '暂无';
  187. $result['unit_id'] = 1;
  188. $result['cash'] = '0.00';
  189. if ($goods_info) {
  190. $where['goods_id'] = $goods_id;
  191. $where['sku_id'] = $sku_id;
  192. $info = array();
  193. # 仓库
  194. $servicer_store_id = Dever::input('servicer_store_id');
  195. if ($servicer_store_id) {
  196. $where['servicer_store_id'] = $servicer_store_id;
  197. $info = Dever::db('scm_servicer/store_goods_sku')->getOne($where);
  198. }
  199. # 获取供应商供货价
  200. $supplier_id = Dever::input('supplier_id');
  201. if ($supplier_id) {
  202. $where['supplier_id'] = $supplier_id;
  203. $sku = Dever::db('scm_supplier/goods_sku')->getOne($where);
  204. }
  205. $result['cash'] = isset($sku['cost_price']) && $sku['cost_price'] ? $sku['cost_price'] : $goods_info['cost_price'];
  206. if ($info) {
  207. $result['goods_id'] = $info['total'] . $goods_info['unit'];
  208. }
  209. $result['unit_id'] = $goods_info['unit_id'];
  210. if ($result['unit_id']) {
  211. $unit = Dever::db('scm_product/info_unit')->select(array('info_id' => $goods_info['id']));
  212. $option['unit_id'] = '';
  213. $unit_info = Dever::db('scm/unit')->find($result['unit_id']);
  214. $option['unit_id'] .= '<option value="'.$unit_info['id'].'" selected>'.$unit_info['name'].'</option>';
  215. if ($unit) {
  216. foreach ($unit as $k => $v) {
  217. $unit_info = Dever::db('scm/unit')->find($v['unit_id']);
  218. $option['unit_id'] .= '<option value="'.$unit_info['id'].'">'.$unit_info['name'].'</option>';
  219. }
  220. }
  221. }
  222. }
  223. return array('data' => $result, 'html' => '', 'option' => $option);
  224. }
  225. # 根据单位获取价格
  226. public function showPriceByUnit_api()
  227. {
  228. $unit = Dever::input('value');
  229. $goods = Dever::input('goods');
  230. list($goods_id, $sku_id) = explode('-', $goods);
  231. $goods_info = Dever::load('scm_product/lib/info')->getBaseInfo($goods_id, $sku_id);
  232. $result = array();
  233. if ($goods_info) {
  234. $where['goods_id'] = $goods_id;
  235. $where['sku_id'] = $sku_id;
  236. # 获取供应商供货价
  237. $supplier_id = Dever::input('supplier_id');
  238. if ($supplier_id) {
  239. $where['supplier_id'] = $supplier_id;
  240. $sku = Dever::db('scm_supplier/goods_sku')->getOne($where);
  241. }
  242. $result['cash'] = isset($sku['cost_price']) && $sku['cost_price'] ? $sku['cost_price'] : $goods_info['cost_price'];
  243. $unit = Dever::db('scm_product/info_unit')->find(array('info_id' => $goods_info['id'], 'unit_id' => $unit));
  244. if ($unit && $unit['discount'] > 0) {
  245. $result['cash'] = $result['cash'] * $unit['radio'] * $unit['discount'];
  246. }
  247. }
  248. return array('data' => $result, 'html' => '');
  249. }
  250. }