Manage.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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. $id = Dever::input('id');
  84. $keyword = Dever::input('keyword');
  85. $where = array();
  86. if ($keyword) {
  87. $where['name'] = $keyword;
  88. }
  89. $data = array();
  90. $cate = '';
  91. $supplier_id = Dever::input('supplier_id');
  92. if ($supplier_id) {
  93. $supplier_goods = Dever::db('scm_supplier/goods')->one(array('supplier_id' => $supplier_id));
  94. if ($supplier_goods) {
  95. $where['supplier_id'] = $supplier_id;
  96. $data = Dever::search('scm_supplier/goods_sku', $where);
  97. } else {
  98. $supplier = Dever::db('scm_supplier/info')->find($supplier_id);
  99. if ($supplier && $supplier['category']) {
  100. $cate = $supplier['category'];
  101. }
  102. }
  103. }
  104. $service_id = Dever::input('service_id');
  105. $servicer_store_id = Dever::input('servicer_store_id');
  106. if ($servicer_store_id) {
  107. $store_goods = Dever::db('scm_servicer/store_goods')->one(array('servicer_store_id' => $servicer_store_id));
  108. if ($store_goods) {
  109. $where['servicer_store_id'] = $servicer_store_id;
  110. $data = Dever::search('scm_servicer/store_goods_list', $where);
  111. } else {
  112. # 没有库存
  113. return array();
  114. }
  115. }
  116. if (!$data) {
  117. $id = Dever::input('where_id');
  118. if ($id) {
  119. $where['id_no'] = $id;
  120. }
  121. if ($cate) {
  122. $where['cate'] = $cate;
  123. }
  124. $data = Dever::search('scm_product/info', $where);
  125. }
  126. if ($data) {
  127. $old = $data;
  128. $data = array();
  129. foreach ($old as $k => $v) {
  130. Dever::load('scm_product/lib/sku')->getList($v, $data);
  131. }
  132. }
  133. $width = '600';
  134. $table = '<style>.layui-table-view{margin:10px!important}</style><table class="layui-table" lay-filter="'.$id.'">';
  135. $table .= '<thead>
  136. <tr>
  137. <th lay-data="{field:\'value\', fixed:\'left\', width: 120}">ID</th>
  138. <th lay-data="{field:\'name\', fixed:\'left\', hide:true}">名称</th>
  139. <th lay-data="{field:\'sname\', fixed:\'left\', width: 120}">名称</th>
  140. <th lay-data="{field:\'spec\'}">规格</th>
  141. </tr>
  142. </thead>';
  143. $table .= '<tbody>';
  144. foreach ($data as $k => $v) {
  145. $table .= '<tr>
  146. <td>'.$v['id'].'</td>
  147. <td>'.$v['name'].'</td>
  148. <td>'.$v['sname'].'</td>
  149. <td>'.$v['spec'].'</td>
  150. </tr>';
  151. }
  152. $table .= '</tbody>';
  153. $table .= '</table>';
  154. $result['list'] = $data;
  155. //$result['table'] = $table;
  156. $result['table_config'] = array('width' => $width);
  157. return $result;
  158. }
  159. public function getGoods($id, $table = 'scm_servicer/in_order_goods', $cash = true)
  160. {
  161. $result = array();
  162. $result['head'] = array('名称', '批次', '单价', '数量', '状态');
  163. if (!$cash) {
  164. unset($result['head'][1]);
  165. }
  166. $result['body'] = array();
  167. $data = Dever::db($table)->select(array('order_id' => $id));
  168. if ($data) {
  169. $status = Dever::db($table)->config['status'];
  170. foreach ($data as $k => $v) {
  171. $goods_info = Dever::load('scm_product/lib/info')->getBaseInfo($v['goods_id'], $v['sku_id']);
  172. $status_name = Dever::status($status, $v['status']);
  173. $unit = Dever::db('scm/unit')->one($v['unit_id']);
  174. $result['body'][$k][] = $goods_info['aname'];
  175. $result['body'][$k][] = $v['batch'];
  176. $result['body'][$k][] = $v['cash'];
  177. $result['body'][$k][] = $v['num'] . $unit['name'];
  178. $result['body'][$k][] = $status_name;
  179. if (!$cash) {
  180. unset($result['body'][$k][1]);
  181. }
  182. }
  183. }
  184. $body[''] = array
  185. (
  186. 'type' => 'table',
  187. 'content' => $result,
  188. );
  189. if ($result['body']) {
  190. return Dever::show('', $body);
  191. } else {
  192. return '暂无';
  193. }
  194. }
  195. public function searchRole_api()
  196. {
  197. $in_type = Dever::input('in_type');
  198. $service_id = Dever::input('service_id');
  199. $servicer_store_id = Dever::input('servicer_store_id');
  200. if ($in_type == 2) {
  201. # 生成仓库入库单
  202. }
  203. }
  204. # 根据商品获取信息,后台入库出库单使用
  205. public function showInfo_api()
  206. {
  207. $goods = Dever::input('value');
  208. $cash_col = Dever::input('cash_col', 'cost_price');
  209. list($goods_id, $sku_id) = explode('-', $goods);
  210. $goods_info = Dever::load('scm_product/lib/info')->getBaseInfo($goods_id, $sku_id);
  211. $option = array();
  212. $result = array();
  213. $result['goods_id'] = '暂无';
  214. $result['unit_id'] = 1;
  215. $result['cash'] = '0.00';
  216. if ($goods_info) {
  217. $result['cash'] = $goods_info[$cash_col];
  218. $string = '';
  219. $table = Dever::input('table');
  220. $unit_id = false;
  221. if ($table == 'in_order') {
  222. $unit_id = -1;
  223. }
  224. $data = Dever::load('scm/lib/unit')->getData($goods_id, $sku_id, $unit_id, Dever::input('supplier_id'), Dever::input('cash_col'));
  225. if ($data) {
  226. $result['cash'] = $data['cash'];
  227. $result['goods_id'] = $data['num'] . $goods_info['unit'] . $string;
  228. }
  229. $result['unit_id'] = $goods_info['unit_id'];
  230. if ($result['unit_id']) {
  231. $unit = Dever::db('scm_product/info_unit')->select(array('info_id' => $goods_info['id']));
  232. $option['unit_id'] = '';
  233. $unit_info = Dever::db('scm/unit')->find($result['unit_id']);
  234. $option['unit_id'] .= '<option value="'.$unit_info['id'].'" selected>'.$unit_info['name'].'</option>';
  235. if ($unit) {
  236. foreach ($unit as $k => $v) {
  237. $unit_info = Dever::db('scm/unit')->find($v['unit_id']);
  238. $option['unit_id'] .= '<option value="'.$unit_info['id'].'">'.$unit_info['name'].'</option>';
  239. }
  240. }
  241. }
  242. $result['cash'] = Dever::number($result['cash']);
  243. $result['num'] = '1.00';
  244. }
  245. return array('data' => $result, 'html' => '', 'option' => $option);
  246. }
  247. # 根据单位获取价格
  248. public function showPriceByUnit_api()
  249. {
  250. $unit = Dever::input('value');
  251. $goods = Dever::input('goods');
  252. $temp = explode('-', $goods);
  253. $goods_id = $temp[0];
  254. $sku_id = $temp[1];
  255. $data = Dever::load('scm/lib/unit')->getData($goods_id, $sku_id, $unit, Dever::input('supplier_id'), Dever::input('cash_col'));
  256. if ($data && $data['num'] > 0) {
  257. $unit = Dever::db('scm/unit')->one($unit);
  258. $data['goods_id'] = $data['num'] . $unit['name'];
  259. }
  260. unset($data['num']);
  261. return array('data' => $data, 'html' => '');
  262. }
  263. }