Manage.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. <?php
  2. namespace Shop\Lib;
  3. use Dever;
  4. class Manage
  5. {
  6. public function sellOrderPs($id, $name, $data)
  7. {
  8. Dever::config('base')->hook = true;
  9. $order_id = Dever::param('order_id', $data);
  10. if ($order_id) {
  11. $info = Dever::db('shop/sell_order')->find(array('id' => $order_id));
  12. if ($info && $info['status'] < 3) {
  13. Dever::load('shop/lib/sell')->notice($info);
  14. }
  15. }
  16. }
  17. # 获取规格型号
  18. public function getSku($goods_id, $sku_id)
  19. {
  20. $goods_info = Dever::load('goods/lib/info')->getInfoBySku($goods_id, $sku_id);
  21. if (isset($goods_info['sku'])) {
  22. $sku = $goods_info['sku']['string'];
  23. } else {
  24. $sku = '';
  25. }
  26. return $sku;
  27. }
  28. # 获取在途库存
  29. public function getGoodsTotal($type, $type_id, $goods_id, $sku_id)
  30. {
  31. $where['type'] = $type;
  32. $where['type_id'] = $type_id;
  33. $where['status'] = '2,3,4';
  34. $where['goods_id'] = $goods_id;
  35. $where['sku_id'] = $sku_id;
  36. $order = Dever::db('shop/buy_order_goods')->getGoodsTotal($where);
  37. if ($order && $order['total']) {
  38. return $order['total'];
  39. }
  40. return 0;
  41. }
  42. public function buyInfoRefundNum($id)
  43. {
  44. $where['status'] = 3;
  45. $where['order_id'] = $id;
  46. $order = Dever::db('shop/buy_order_goods')->getGoodsNum($where);
  47. if ($order && $order['total']) {
  48. return $order['total'];
  49. }
  50. return 0;
  51. }
  52. public function buyInfoRefundStatus($id, $table = 'buy_order')
  53. {
  54. $info = Dever::db('shop/' . $table)->find($id);
  55. if ($info['refund_cash'] > 0) {
  56. if ($info['status'] == 6 || $info['status'] == 8) {
  57. return '已退款';
  58. } else {
  59. return '有退款';
  60. }
  61. } elseif ($info['refund_status'] == 2) {
  62. return '已申请';
  63. } else {
  64. return '未申请';
  65. }
  66. }
  67. public function shopInfoType($type)
  68. {
  69. $config_type = Dever::db('shop/info')->config['config_type'];
  70. return $config_type[$type];
  71. }
  72. public function getTotalCash($id)
  73. {
  74. $order = Dever::db('shop/sell_order')->one($id);
  75. $cash = 0;
  76. $cash = $order['oprice'];
  77. return round($cash, 2);
  78. }
  79. public function getOrderUrl($order_id, $order_num, $search)
  80. {
  81. //$url = Dever::load('manage/database')->url('list', $order_id, 'buy_order_goods&project=shop&order_id='.$order_id.'&page_type=1');
  82. $url = Dever::url('project/database/list?project=cash&search_option_search=1&search_option_type=1&page_type=2&table=buy_order_goods&project=shop&order_id='.$order_id.'&page_type=1&menu=cash&menu_id=124&search_option_state=1', 'manage');
  83. if ($search == 3) {
  84. $url .= '&type=2&search_option_type=2';
  85. } elseif ($search == 2) {
  86. $url .= '&type=1&search_option_type=3';
  87. } else {
  88. $url .= '&type=1&search_option_type=1';
  89. }
  90. $url = '<a href="'.$url.'">'.$order_num.'</a>';
  91. return $url;
  92. }
  93. public function showCash($cash, $p_cash = 0)
  94. {
  95. if (!$cash) {
  96. $cash = 0;
  97. }
  98. if (!$p_cash) {
  99. $p_cash = 0;
  100. }
  101. return $cash - $p_cash;
  102. }
  103. # 获取用户信息
  104. public function user($id, $type = 1)
  105. {
  106. $info = Dever::db('shop/sell_order')->one($id);
  107. if ($info['uid'] && $info['uid'] > 0) {
  108. $user = Dever::db('passport/user')->one($info['uid']);
  109. $result = $user['username'];
  110. if ($type == 1 && $info['mobile']) {
  111. $result .= '('.$info['mobile'].')';
  112. }
  113. } else {
  114. $result = $info['mobile'];
  115. }
  116. return $result;
  117. }
  118. # 获取订单信息
  119. public function sell_order($id)
  120. {
  121. $table = array();
  122. $info = Dever::db('shop/sell_order')->one($id);
  123. $goods = Dever::db('shop/sell_order_goods')->select(array('order_id' => $info['id']));
  124. foreach ($goods as $k => $v) {
  125. $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v['goods_id'], $v['sku_id']);
  126. //print_r($goods_info);die;
  127. $table[$goods_info['name']] = $v['price'];
  128. }
  129. return Dever::table($table);
  130. }
  131. /**
  132. * 更新信息
  133. *
  134. * @return mixed
  135. */
  136. public function upInfo($id, $name, $data)
  137. {
  138. Dever::config('base')->hook = true;
  139. }
  140. /**
  141. * 更新信息
  142. *
  143. * @return mixed
  144. */
  145. public function printInsert($id, $name, $data)
  146. {
  147. Dever::config('base')->hook = true;
  148. $name = Dever::param('name', $data);
  149. $number = Dever::param('number', $data);
  150. $phonenum = Dever::param('phonenum', $data);
  151. $key = Dever::param('key', $data);
  152. if ($number && $key) {
  153. $data = array();
  154. $data['name'] = $name;
  155. $data['number'] = $number;
  156. $data['phonenum'] = $phonenum;
  157. $data['key'] = $key;
  158. $result = Dever::load('mshop/lib/feieyun')->add(array($data));
  159. if (isset($result['no'][0]) && $result['no'][0] && strstr($result['no'][0], '编号不合法')) {
  160. Dever::db('shop/print')->update(array('where_id' => $id, 'status' => 10));
  161. } else {
  162. Dever::db('shop/print')->update(array('where_id' => $id, 'status' => 1));
  163. }
  164. }
  165. }
  166. /**
  167. * 更新信息
  168. *
  169. * @return mixed
  170. */
  171. public function printUpdate($id, $name, $data)
  172. {
  173. Dever::config('base')->hook = true;
  174. $info = Dever::db('shop/print')->one($id);
  175. $name = Dever::param('name', $data);
  176. $phonenum = Dever::param('phonenum', $data);
  177. if ($info && $name) {
  178. if ($info['status'] == 10) {
  179. $this->printInsert($id, $name, $info);
  180. } else {
  181. Dever::load('mshop/lib/feieyun')->edit($info['number'], $name, $phonenum);
  182. }
  183. }
  184. }
  185. /**
  186. * 打印机状态
  187. *
  188. * @return mixed
  189. */
  190. public function printStatus($status, $sn)
  191. {
  192. return $status >= 10 ? '绑定失败' : Dever::load('mshop/lib/feieyun')->status($sn);
  193. }
  194. public function buyOrderUpdate($id, $name, $data)
  195. {
  196. Dever::config('base')->hook = true;
  197. $update = array();
  198. $audit = Dever::param('audit', $data);
  199. $info = Dever::db('shop/buy_order')->one($id);
  200. if ($audit > 1 && $info && $info['status'] == 2) {
  201. if ($audit == 2) {
  202. # 成功
  203. Dever::setInput('order_id', $id);
  204. Dever::load('mshop/lib/buy.audit_commit');
  205. } else {
  206. # 退款
  207. $shop = Dever::db('shop/info')->find($info['type_id']);
  208. Dever::load('shop/lib/refund')->set('buy')->apply(1, $shop['id'], $id, false, 3, 0, '未通过审核');
  209. }
  210. }
  211. }
  212. public function sellOrderUpdate($id, $name, $data)
  213. {
  214. Dever::config('base')->hook = true;
  215. $update = array();
  216. $audit = Dever::param('audit', $data);
  217. $info = Dever::db('shop/sell_order')->one($id);
  218. if ($audit > 1 && $info && $info['status'] == 2) {
  219. if ($audit == 2) {
  220. # 成功
  221. Dever::setInput('order_id', $id);
  222. Dever::load('shop/lib/sell.audit_commit');
  223. } else {
  224. # 退款
  225. $shop = Dever::db('shop/info')->find($info['shop_id']);
  226. Dever::load('shop/lib/refund')->set('sell')->apply(1, $shop['id'], $id, false, 3, 0, '未通过审核');
  227. }
  228. }
  229. }
  230. /**
  231. * 更新信息
  232. *
  233. * @return mixed
  234. */
  235. public function couponUpdate($id, $name, $data)
  236. {
  237. Dever::config('base')->hook = true;
  238. $update = array();
  239. $coupon = Dever::param('coupon', $data);
  240. if ($coupon) {
  241. $temp = is_string($coupon) ? explode(',', $coupon) : $coupon;
  242. $update['method'] = $temp[0];
  243. $update['coupon_id'] = $temp[1];
  244. }
  245. $shop_id = Dever::param('shop_id', $data);
  246. if ($shop_id) {
  247. $shop = Dever::db('shop/info')->find($shop_id);
  248. $update['city'] = $shop['city'];
  249. }
  250. if (isset($update) && $update) {
  251. $update['where_id'] = $id;
  252. Dever::db('shop/coupon')->update($update);
  253. }
  254. }
  255. /**
  256. * 更新信息
  257. *
  258. * @return mixed
  259. */
  260. public function infoUpdate($id, $name, $data)
  261. {
  262. $update = array();
  263. $area = Dever::param('area', $data);
  264. if ($area) {
  265. $temp = is_string($area) ? explode(',', $area) : $area;
  266. $update['province'] = $temp[0];
  267. $update['city'] = $temp[1];
  268. if (isset($temp[2])) {
  269. $update['county'] = $temp[2];
  270. }
  271. if (isset($temp[3])) {
  272. $update['town'] = $temp[3];
  273. }
  274. if (is_array($area)) {
  275. $area = implode(',', $area);
  276. }
  277. $gup['option_shop_id'] = $id;
  278. $gup['set_area'] = $area;
  279. Dever::db('shop/goods_sku')->updates($gup);
  280. Dever::db('shop/sell_order')->updates($gup);
  281. unset($gup['option_shop_id']);
  282. $gup['option_type_id'] = $id;
  283. $gup['option_type'] = 1;
  284. Dever::db('shop/buy_order')->updates($gup);
  285. Dever::db('shop/out_order')->updates($gup);
  286. }
  287. $address = Dever::param('address', $data);
  288. if ($address && isset($update['city'])) {
  289. $geo = Dever::load('shop/lib/info')->geo($update['city'], $address);
  290. $update['lng'] = $geo[0];
  291. $update['lat'] = $geo[1];
  292. $update['map'] = $geo[2];
  293. $update['coord_address'] = $address;
  294. }
  295. /*
  296. $map = Dever::param('map', $data);
  297. if ($map) {
  298. $temp = is_string($map) ? explode(',', $map) : $map;
  299. if (isset($temp[1])) {
  300. $update['lng'] = $temp[1];
  301. $update['lat'] = $temp[2];
  302. $address = Dever::param('address', $data);
  303. $update['coord_address'] = Dever::load('shop/lib/info')->address($temp[1], $temp[2]);
  304. if (!$address && $update['coord_address']) {
  305. $update['address'] = $update['coord_address'];
  306. }
  307. }
  308. }
  309. */
  310. $act = Dever::param('act', $data);
  311. if ($act) {
  312. foreach ($act as $k => $v) {
  313. $w = array();
  314. $w['shop_id'] = $id;
  315. $w['act_id'] = $k;
  316. foreach ($v as $k1 => $v1) {
  317. $w['shop_coupon_id'] = $v1;
  318. $info = Dever::db('shop/coupon_act')->find($w);
  319. if (!$info) {
  320. Dever::db('shop/coupon_act')->insert($w);
  321. }
  322. }
  323. }
  324. }
  325. //Dever::upLinkage($update, $id, $data, 'goods', 'shop/goods', 'shop_id', 'goods_id', 'category_id');
  326. //Dever::upLinkage($update, $id, $data, 'factory', 'shop/factory', 'shop_id', 'factory_id', 'city');
  327. //Dever::upLinkage($update, $id, $data, 'store', 'shop/store', 'shop_id', 'store_id', 'city');
  328. if (isset($update) && $update) {
  329. $update['where_id'] = $id;
  330. Dever::db('shop/info')->update($update);
  331. }
  332. $truename = Dever::param('truename', $data);
  333. $mobile = Dever::param('mobile', $data);
  334. if ($mobile) {
  335. $member = Dever::db('shop/member')->one(array('shop_id' => $id, 'mobile' => $mobile));
  336. $update = array();
  337. $update['shop_id'] = $id;
  338. $update['name'] = $truename;
  339. $update['mobile'] = $mobile;
  340. if ($member) {
  341. $update['where_id'] = $member['id'];
  342. Dever::db('shop/member')->update($update);
  343. } else {
  344. Dever::db('shop/member')->insert($update);
  345. }
  346. }
  347. }
  348. private function updateParam()
  349. {
  350. }
  351. /**
  352. * 更新商品信息
  353. *
  354. * @return mixed
  355. */
  356. public function goodsUpdate($id, $name, $data)
  357. {
  358. $update = array();
  359. $state = Dever::param('state', $data);
  360. if ($state) {
  361. Dever::config('base')->after = true;
  362. $info = Dever::db('shop/goods')->one($id);
  363. $shop_id = $info['shop_id'];
  364. $shop = Dever::db('shop/info')->one($shop_id);
  365. if ($shop && $shop['goods']) {
  366. $goods = Dever::json_decode($shop['goods']);
  367. if (isset($goods['level_' . $info['category_id']]['value']['id_' . $info['goods_id']])) {
  368. if ($state == 2) {
  369. unset($goods['level_' . $info['category_id']]['value']['id_' . $info['goods_id']]);
  370. }
  371. if (count($goods['level_' . $info['category_id']]['value']) <= 0) {
  372. unset($goods['level_' . $info['category_id']]);
  373. }
  374. } elseif ($state == 1) {
  375. $goods_info = Dever::db('goods/info')->one($info['goods_id']);
  376. $cate = Dever::load('category/api')->string($info['category_id']);
  377. $goods['level_' . $info['category_id']]['id'] = $info['category_id'];
  378. $goods['level_' . $info['category_id']]['name'] = $cate;
  379. $goods['level_' . $info['category_id']]['value']['id_' . $info['goods_id']] = array
  380. (
  381. 'id' => $info['goods_id'],
  382. 'name' => $goods_info['name'],
  383. 'state' => 1,
  384. );
  385. }
  386. $set['goods'] = Dever::json_encode($goods);
  387. $set['where_id'] = $shop_id;
  388. Dever::db('shop/info')->update($set);
  389. }
  390. }
  391. }
  392. /**
  393. * 更新库存信息
  394. *
  395. * @return mixed
  396. */
  397. public function skuUpdate($id, $name, $data)
  398. {
  399. $update = array();
  400. $add_num = Dever::param('add_num', $data);
  401. if ($add_num) {
  402. $state = Dever::db('shop/goods_sku')->updateTotal(array('where_id' => $id, 'total_num' => $add_num));
  403. if ($state) {
  404. $state = Dever::db('shop/goods_sku')->update(array('where_id' => $id, 'add_num' => 0));
  405. $info = Dever::db('shop/goods_sku')->one($id);
  406. $goods = Dever::db('shop/goods')->one(array('goods_id' => $info['goods_id'], 'shop_id' => $info['shop_id']));
  407. if ($goods) {
  408. Dever::db('shop/goods')->update(array('where_id' => $goods['id'], 'total_num' => $info['total_num'], 'add_num' => 0));
  409. }
  410. if ($add_num < 0) {
  411. # 记录出库日志
  412. } else {
  413. # 记录入库日志
  414. }
  415. }
  416. }
  417. }
  418. # 获取供货商信息
  419. public function buyInfo($type = '', $type_id = '')
  420. {
  421. if ($type == 1) {
  422. $type_info = Dever::db('shop/info')->one($type_id);
  423. return $type_info['name'] . '('.$type_info['mobile'].')';
  424. } elseif ($type == 2) {
  425. $type_info = Dever::db('store/info')->one($type_id);
  426. $sign = Dever::login($type_id);
  427. $link = Dever::url('home?sign=' . $sign, 'store');
  428. //return $type_info['name'] . '('.$type_info['mobile'].')<br /><a href="'.$link.'" target="_blank">进入仓库管理</a>';
  429. return $type_info['name'] . '('.$type_info['mobile'].')';
  430. } elseif ($type == 3) {
  431. $sign = Dever::login($type_id);
  432. $link = Dever::url('home?sign=' . $sign, 'factory');
  433. $type_info = Dever::db('factory/info')->one($type_id);
  434. //return $type_info['name'] . '('.$type_info['mobile'].')<br /><a href="'.$link.'" target="_blank">进入工厂管理</a>';
  435. return $type_info['name'] . '('.$type_info['mobile'].')';
  436. } else {
  437. return '无';
  438. }
  439. }
  440. /**
  441. * 更新信息
  442. *
  443. * @return mixed
  444. */
  445. public function buyOrderPs($id, $name, $data)
  446. {
  447. $order_id = Dever::param('order_id', $data);
  448. if ($order_id) {
  449. $update['where_id'] = $order_id;
  450. $update['set_status'] = 4;
  451. Dever::db('shop/buy_order')->update($update);
  452. }
  453. }
  454. # 获取门店
  455. public function search_api()
  456. {
  457. return Dever::search('shop/info');
  458. }
  459. # 获取环比增长
  460. public function getGoodsHb($num, $day, $goods_id)
  461. {
  462. $where = array('day' => $day, 'goods_id' => $goods_id);
  463. $search = Dever::search_button();
  464. if ($search) {
  465. $where['config']['group'] = $search[0];
  466. $where['config']['col'] = str_replace('|id', '', $search[1]);
  467. }
  468. if ($num < 0) {
  469. $num = 0;
  470. }
  471. $prev = Dever::db('shop/goods_stat')->prev($where);
  472. if ($prev && $num > 0 && $prev['num'] >= 0) {
  473. $n = $prev['num'];
  474. if ($n == 0) {
  475. $n = 1;
  476. }
  477. $hb = round(($num-$prev['num'])/$n, 2)*100;
  478. } else {
  479. $hb = 0;
  480. }
  481. return $hb . '%';
  482. }
  483. public function getUserHb($num, $total, $day)
  484. {
  485. $result = $this->getUserStat($num, $total, 0);
  486. $where = array('day' => $day);
  487. $search = Dever::search_button();
  488. if ($search) {
  489. $where['config']['group'] = $search[0];
  490. $where['config']['col'] = str_replace('|id', '', $search[1]);
  491. }
  492. $hb = 0;
  493. $prev = Dever::db('shop/user_stat')->prev($where);
  494. if ($prev) {
  495. $prev = $this->getUserStat($prev['num'], $prev['total'], $prev['order_num']);
  496. if ($result['fg'] > 0 && $prev['fg'] >= 0) {
  497. $fg = $prev['fg'];
  498. if ($fg == 0) {
  499. $fg = 1;
  500. }
  501. $hb = round(($result['fg']-$prev['fg'])/$fg, 2)*100;
  502. }
  503. }
  504. return $hb . '%';
  505. }
  506. public function getUserStat($num, $total, $order_num)
  507. {
  508. //print_r($info);die;
  509. if ($num && $total) {
  510. $result['fg'] = round($num/$total, 2);
  511. } else {
  512. $result['fg'] = 0;
  513. }
  514. if ($order_num) {
  515. $result['per_num'] = round($order_num/$total, 2);
  516. } else {
  517. $result['per_num'] = 0;
  518. }
  519. return $result;
  520. }
  521. # 获取环比增长
  522. public function getUserRankHb($num, $mobile, $day)
  523. {
  524. $where = array('day' => $day, 'mobile' => $mobile);
  525. $search = Dever::search_button();
  526. if ($search) {
  527. $where['config']['group'] = $search[0];
  528. $where['config']['col'] = str_replace('|id', '', $search[1]);
  529. }
  530. if ($num < 0) {
  531. $num = 0;
  532. }
  533. $prev = Dever::db('shop/user_rank_stat')->prev($where);
  534. if ($prev && $num > 0 && $prev['num'] >= 0) {
  535. $n = $prev['num'];
  536. if ($n == 0) {
  537. $n = 1;
  538. }
  539. $hb = round(($num-$prev['num'])/$n, 2)*100;
  540. } else {
  541. $hb = 0;
  542. }
  543. return $hb . '%';
  544. }
  545. # 确认收货
  546. public function setSellOrderStatus_api()
  547. {
  548. $order_id = Dever::input('order_id');
  549. $info = Dever::db('shop/sell_order')->find($order_id);
  550. if ($info) {
  551. Dever::load('shop/lib/sell')->finish($info, $info['shop_id']);
  552. return 'reload';
  553. } else {
  554. Dever::alert('错误的订单号');
  555. }
  556. }
  557. public function searchName($where)
  558. {
  559. $data = Dever::db('store/info')->like($where);
  560. if (!$data) {
  561. $data = Dever::db('shop/info')->like($where);
  562. }
  563. return $data;
  564. }
  565. public function searchFName($where)
  566. {
  567. $data = Dever::db('store/info')->like($where);
  568. if (!$data) {
  569. $data = Dever::db('factory/info')->like($where);
  570. }
  571. return $data;
  572. }
  573. }