Manage.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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. public function selectSource_api()
  12. {
  13. $value = Dever::input('value');
  14. $id = Dever::input('id');
  15. $data = array();
  16. if ($id) {
  17. $data = Dever::db('scm_product/info')->find($id);
  18. if ($value != $data['source_type']) {
  19. $data['source_id'] = -1;
  20. }
  21. }
  22. $config['source_id'] = Dever::db('scm_product/info')->config['struct']['source_id'];
  23. $config['source_id']['update'] = 'select';
  24. $config['source_id']['update_search'] = 'scm/lib/role.search?source_type=' . $value;
  25. $result = Dever::load('manage/database')->update_struct(array('struct' => $config), false, $data, -1, '', true);
  26. return $result;
  27. }
  28. /**
  29. * 更新信息
  30. *
  31. * @return mixed
  32. */
  33. public function updateInfo($id, $name, $data)
  34. {
  35. # 更新分类id
  36. $category = Dever::param('category', $data);
  37. if ($category) {
  38. if (is_array($category)) {
  39. $category_id = end($category);
  40. $top_category_id = $category[0];
  41. if (isset($category[1])) {
  42. $second_category_id = $category[1];
  43. } else {
  44. $second_category_id = $category[0];
  45. }
  46. } else {
  47. $category_id = $category;
  48. $top_category_id = $category;
  49. $second_category_id = $category;
  50. }
  51. $update['top_category_id'] = $top_category_id;
  52. $update['second_category_id'] = $second_category_id;
  53. $update['category_id'] = $category_id;
  54. }
  55. if (isset($update)) {
  56. $update['where_id'] = $id;
  57. Dever::db('scm_product/info')->update($update);
  58. }
  59. }
  60. public function updateCategory($id, $name, $data)
  61. {
  62. $info = Dever::param('category', $data);
  63. if ($info && $info != -1) {
  64. $update['top_category_id'] = $info[0];
  65. $num = count($info)+1;
  66. $update['level'] = $num;
  67. $parent = Dever::param('category_id', $data);
  68. $child = Dever::db('scm_product/category')->one(array('category_id' => $id));
  69. if (!$child) {
  70. $update['level'] = -1;
  71. }
  72. Dever::db('scm_product/category')->update(array('where_id' => $parent, 'level' => $num - 1));
  73. } else {
  74. $update['level'] = 1;
  75. $update['top_category_id'] = -1;
  76. }
  77. if (isset($update)) {
  78. $update['where_id'] = $id;
  79. Dever::db('scm_product/category')->update($update);
  80. }
  81. }
  82. /**
  83. * 更新属性信息
  84. *
  85. * @return mixed
  86. */
  87. public function updateAttr($id, $name, $data)
  88. {
  89. return;
  90. $is_sell = Dever::param('is_sell', $data);
  91. if ($is_sell > 1) {
  92. $update['type'] = 11;
  93. }
  94. if (isset($update)) {
  95. $update['where_id'] = $id;
  96. Dever::db('scm_product/category_attr')->update($update);
  97. }
  98. }
  99. public function searchProduct_api()
  100. {
  101. $id = Dever::input('id');
  102. $keyword = Dever::input('keyword');
  103. $where = array();
  104. if ($keyword) {
  105. $where['name'] = $keyword;
  106. }
  107. $data = array();
  108. $cate = '';
  109. $supplier_id = Dever::input('supplier_id');
  110. if ($supplier_id) {
  111. $where['supplier_id'] = $supplier_id;
  112. $data = Dever::search('scm_supplier/goods', $where);
  113. if (!$data) {
  114. $supplier = Dever::db('scm_supplier/info')->find($supplier_id);
  115. if ($supplier && $supplier['category']) {
  116. $cate = $supplier['category'];
  117. }
  118. }
  119. }
  120. $seller_id = Dever::input('seller_id');
  121. if ($seller_id) {
  122. $where['seller_id'] = $seller_id;
  123. $data = Dever::search('scm_seller/goods', $where);
  124. if (!$data) {
  125. $seller = Dever::db('scm_seller/info')->find($seller_id);
  126. if ($seller && $seller['category']) {
  127. $cate = $seller['category'];
  128. }
  129. }
  130. }
  131. $service_id = Dever::input('service_id');
  132. $servicer_store_id = Dever::input('servicer_store_id');
  133. if ($servicer_store_id) {
  134. $where['servicer_store_id'] = $servicer_store_id;
  135. $data = Dever::search('scm_servicer/store_goods', $where);
  136. }
  137. if (!$data) {
  138. $id = Dever::input('where_id');
  139. if ($id) {
  140. $where['id_no'] = $id;
  141. }
  142. if ($cate) {
  143. $where['cate'] = $cate;
  144. }
  145. $data = Dever::search('scm_product/info', $where);
  146. }
  147. if ($data) {
  148. $old = $data;
  149. $data = array();
  150. foreach ($old as $k => $v) {
  151. Dever::load('scm_product/lib/sku')->getList($v, $data);
  152. }
  153. }
  154. $width = '600';
  155. $table = '<style>.layui-table-view{margin:10px!important}</style><table class="layui-table" lay-filter="'.$id.'">';
  156. $table .= '<thead>
  157. <tr>
  158. <th lay-data="{field:\'value\', fixed:\'left\', width: 120}">ID</th>
  159. <th lay-data="{field:\'name\', fixed:\'left\', hide:true}">名称</th>
  160. <th lay-data="{field:\'sname\', fixed:\'left\', width: 120}">名称</th>
  161. <th lay-data="{field:\'spec\'}">规格</th>
  162. </tr>
  163. </thead>';
  164. $table .= '<tbody>';
  165. foreach ($data as $k => $v) {
  166. $table .= '<tr>
  167. <td>'.$v['id'].'</td>
  168. <td>'.$v['name'].'</td>
  169. <td>'.$v['sname'].'</td>
  170. <td>'.$v['spec'].'</td>
  171. </tr>';
  172. }
  173. $table .= '</tbody>';
  174. $table .= '</table>';
  175. $result['list'] = $data;
  176. //$result['table'] = $table;
  177. $result['table_config'] = array('width' => $width);
  178. return $result;
  179. }
  180. public function getGoods($id, $table = 'scm_servicer/in_order_goods', $cash = true)
  181. {
  182. $result = array();
  183. $result['head'] = array('名称', '批次', '单价', '数量', '状态');
  184. if (!$cash) {
  185. unset($result['head'][1]);
  186. }
  187. $result['body'] = array();
  188. $data = Dever::db($table)->select(array('order_id' => $id));
  189. if ($data) {
  190. $status = Dever::db($table)->config['status'];
  191. foreach ($data as $k => $v) {
  192. $goods_info = Dever::load('scm_product/lib/info')->getBaseInfo($v['goods_id'], $v['sku_id']);
  193. $status_name = Dever::status($status, $v['status']);
  194. $unit = Dever::db('scm/unit')->one($v['unit_id']);
  195. $result['body'][$k][] = $goods_info['aname'];
  196. if (isset($v['batch'])) {
  197. $result['body'][$k][] = $v['batch'];
  198. } else {
  199. unset($result['head'][1]);
  200. }
  201. $result['body'][$k][] = $v['cash'];
  202. $result['body'][$k][] = $v['num'] . $unit['name'];
  203. $result['body'][$k][] = $status_name;
  204. if (!$cash) {
  205. unset($result['body'][$k][1]);
  206. }
  207. }
  208. }
  209. $body[''] = array
  210. (
  211. 'type' => 'table',
  212. 'content' => $result,
  213. );
  214. if ($result['body']) {
  215. return Dever::show('', $body);
  216. } else {
  217. return '暂无';
  218. }
  219. }
  220. public function searchRole_api()
  221. {
  222. $in_type = Dever::input('in_type');
  223. $service_id = Dever::input('service_id');
  224. $servicer_store_id = Dever::input('servicer_store_id');
  225. if ($in_type == 2) {
  226. # 生成仓库入库单
  227. }
  228. }
  229. # 根据商品获取信息,后台入库出库单使用
  230. public function showInfo_api()
  231. {
  232. $goods = Dever::input('value');
  233. $cash_col = Dever::input('cash_col', 'cost_price');
  234. list($goods_id, $sku_id) = explode('-', $goods);
  235. $goods_info = Dever::load('scm_product/lib/info')->getBaseInfo($goods_id, $sku_id);
  236. $option = array();
  237. $result = array();
  238. $result['goods_id'] = '暂无';
  239. $result['unit_id'] = 1;
  240. $result['cash'] = '0.00';
  241. if ($goods_info) {
  242. $result['cash'] = $goods_info[$cash_col];
  243. $string = '';
  244. $table = Dever::input('table');
  245. $unit_id = false;
  246. if ($table != 'out_order') {
  247. # 出库不需要
  248. $unit_id = -1;
  249. }
  250. $data = Dever::load('scm/lib/unit')->getData($goods_id, $sku_id, $unit_id, Dever::input('cash_col'));
  251. if ($data) {
  252. $result['cash'] = $data['cash'];
  253. $result['goods_id'] = $data['num'] . $goods_info['unit'] . $string;
  254. }
  255. $result['unit_id'] = $goods_info['unit_id'];
  256. if ($result['unit_id']) {
  257. $unit = Dever::db('scm_product/info_unit')->select(array('info_id' => $goods_info['id']));
  258. $option['unit_id'] = '';
  259. $unit_info = Dever::db('scm/unit')->find($result['unit_id']);
  260. $option['unit_id'] .= '<option value="'.$unit_info['id'].'" selected>'.$unit_info['name'].'</option>';
  261. if ($unit) {
  262. foreach ($unit as $k => $v) {
  263. $unit_info = Dever::db('scm/unit')->find($v['unit_id']);
  264. $option['unit_id'] .= '<option value="'.$unit_info['id'].'">'.$unit_info['name'].'</option>';
  265. }
  266. }
  267. }
  268. $result['cash'] = Dever::number($result['cash']);
  269. $result['num'] = '1.00';
  270. }
  271. return array('data' => $result, 'html' => '', 'option' => $option);
  272. }
  273. # 根据单位获取价格
  274. public function showPriceByUnit_api()
  275. {
  276. $unit = Dever::input('value');
  277. $goods = Dever::input('goods');
  278. $temp = explode('-', $goods);
  279. $goods_id = $temp[0];
  280. $sku_id = $temp[1];
  281. $data = Dever::load('scm/lib/unit')->getData($goods_id, $sku_id, $unit, Dever::input('cash_col'));
  282. if ($data && $data['num'] > 0) {
  283. $unit = Dever::db('scm/unit')->one($unit);
  284. $data['goods_id'] = $data['num'] . $unit['name'];
  285. }
  286. unset($data['num']);
  287. return array('data' => $data, 'html' => '');
  288. }
  289. }