Manage.php 10 KB

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