Manage.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. <?php
  2. namespace Shop\Lib;
  3. use Dever;
  4. class Manage
  5. {
  6. public function getOrderUrl($order_id, $order_num, $search)
  7. {
  8. $url = Dever::load('manage/database')->url('list', $order_id, 'buy_order_goods&project=shop&order_id='.$order_id.'&page_type=1');
  9. if ($search == 3) {
  10. $url .= '&type=2&search_option_type=2';
  11. } elseif ($search == 2) {
  12. $url .= '&type=1&search_option_type=3';
  13. } else {
  14. $url .= '&type=1&search_option_type=1';
  15. }
  16. $url = '<a href="'.$url.'">'.$order_num.'</a>';
  17. return $url;
  18. }
  19. public function showCash($cash, $p_cash = 0)
  20. {
  21. if (!$cash) {
  22. $cash = 0;
  23. }
  24. if (!$p_cash) {
  25. $p_cash = 0;
  26. }
  27. return $cash - $p_cash;
  28. }
  29. # 获取用户信息
  30. public function user($id)
  31. {
  32. $info = Dever::db('shop/sell_order')->one($id);
  33. if ($info['uid'] && $info['uid'] > 0) {
  34. $user = Dever::db('passport/user')->one($info['uid']);
  35. $result = $user['username'];
  36. if ($info['mobile']) {
  37. $result .= '('.$info['mobile'].')';
  38. }
  39. } else {
  40. $result = $info['mobile'];
  41. }
  42. return $result;
  43. }
  44. # 获取订单信息
  45. public function sell_order($id)
  46. {
  47. $table = array();
  48. $info = Dever::db('shop/sell_order')->one($id);
  49. $goods = Dever::db('shop/sell_order_goods')->select(array('order_id' => $info['id']));
  50. foreach ($goods as $k => $v) {
  51. $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v['goods_id'], $v['sku_id']);
  52. //print_r($goods_info);die;
  53. $table[$goods_info['name']] = $v['price'];
  54. }
  55. return Dever::table($table);
  56. }
  57. /**
  58. * 更新信息
  59. *
  60. * @return mixed
  61. */
  62. public function upInfo($id, $name, $data)
  63. {
  64. Dever::config('base')->hook = true;
  65. }
  66. /**
  67. * 更新信息
  68. *
  69. * @return mixed
  70. */
  71. public function printInsert($id, $name, $data)
  72. {
  73. Dever::config('base')->hook = true;
  74. $name = Dever::param('name', $data);
  75. $number = Dever::param('number', $data);
  76. $phonenum = Dever::param('phonenum', $data);
  77. $key = Dever::param('key', $data);
  78. if ($number && $key) {
  79. $data = array();
  80. $data['name'] = $name;
  81. $data['number'] = $number;
  82. $data['phonenum'] = $phonenum;
  83. $data['key'] = $key;
  84. $result = Dever::load('mshop/lib/feieyun')->add(array($data));
  85. if (isset($result['no'][0]) && $result['no'][0] && strstr($result['no'][0], '编号不合法')) {
  86. Dever::db('shop/print')->update(array('where_id' => $id, 'status' => 10));
  87. } else {
  88. Dever::db('shop/print')->update(array('where_id' => $id, 'status' => 1));
  89. }
  90. }
  91. }
  92. /**
  93. * 更新信息
  94. *
  95. * @return mixed
  96. */
  97. public function printUpdate($id, $name, $data)
  98. {
  99. Dever::config('base')->hook = true;
  100. $info = Dever::db('shop/print')->one($id);
  101. $name = Dever::param('name', $data);
  102. $phonenum = Dever::param('phonenum', $data);
  103. if ($info && $name) {
  104. if ($info['status'] == 10) {
  105. $this->printInsert($id, $name, $info);
  106. } else {
  107. Dever::load('mshop/lib/feieyun')->edit($info['number'], $name, $phonenum);
  108. }
  109. }
  110. }
  111. /**
  112. * 打印机状态
  113. *
  114. * @return mixed
  115. */
  116. public function printStatus($status, $sn)
  117. {
  118. return $status >= 10 ? '绑定失败' : Dever::load('mshop/lib/feieyun')->status($sn);
  119. }
  120. /**
  121. * 更新信息
  122. *
  123. * @return mixed
  124. */
  125. public function couponUpdate($id, $name, $data)
  126. {
  127. Dever::config('base')->hook = true;
  128. $update = array();
  129. $coupon = Dever::param('coupon', $data);
  130. if ($coupon) {
  131. $temp = is_string($coupon) ? explode(',', $coupon) : $coupon;
  132. $update['method'] = $temp[0];
  133. $update['coupon_id'] = $temp[1];
  134. }
  135. $shop_id = Dever::param('shop_id', $data);
  136. if ($shop_id) {
  137. $shop = Dever::db('shop/info')->find($shop_id);
  138. $update['city'] = $shop['city'];
  139. }
  140. if (isset($update) && $update) {
  141. $update['where_id'] = $id;
  142. Dever::db('shop/coupon')->update($update);
  143. }
  144. }
  145. /**
  146. * 更新信息
  147. *
  148. * @return mixed
  149. */
  150. public function infoUpdate($id, $name, $data)
  151. {
  152. $update = array();
  153. $area = Dever::param('area', $data);
  154. if ($area) {
  155. $temp = is_string($area) ? explode(',', $area) : $area;
  156. $update['province'] = $temp[0];
  157. $update['city'] = $temp[1];
  158. if (isset($temp[2])) {
  159. $update['county'] = $temp[2];
  160. }
  161. if (isset($temp[3])) {
  162. $update['town'] = $temp[3];
  163. }
  164. }
  165. $map = Dever::param('map', $data);
  166. if ($map) {
  167. $temp = is_string($map) ? explode(',', $map) : $map;
  168. if (isset($temp[1])) {
  169. $update['lng'] = $temp[1];
  170. $update['lat'] = $temp[2];
  171. $address = Dever::param('address', $data);
  172. $update['coord_address'] = Dever::load('shop/lib/info')->address($temp[1], $temp[2]);
  173. if (!$address && $update['coord_address']) {
  174. $update['address'] = $update['coord_address'];
  175. }
  176. }
  177. }
  178. $act = Dever::param('act', $data);
  179. if ($act) {
  180. foreach ($act as $k => $v) {
  181. $w = array();
  182. $w['shop_id'] = $id;
  183. $w['act_id'] = $k;
  184. foreach ($v as $k1 => $v1) {
  185. $w['shop_coupon_id'] = $v1;
  186. $info = Dever::db('shop/coupon_act')->find($w);
  187. if (!$info) {
  188. Dever::db('shop/coupon_act')->insert($w);
  189. }
  190. }
  191. }
  192. }
  193. //Dever::upLinkage($update, $id, $data, 'goods', 'shop/goods', 'shop_id', 'goods_id', 'category_id');
  194. //Dever::upLinkage($update, $id, $data, 'factory', 'shop/factory', 'shop_id', 'factory_id', 'city');
  195. //Dever::upLinkage($update, $id, $data, 'store', 'shop/store', 'shop_id', 'store_id', 'city');
  196. if (isset($update) && $update) {
  197. $update['where_id'] = $id;
  198. Dever::db('shop/info')->update($update);
  199. }
  200. $truename = Dever::param('truename', $data);
  201. $mobile = Dever::param('mobile', $data);
  202. if ($mobile) {
  203. $member = Dever::db('shop/member')->one(array('shop_id' => $id, 'mobile' => $mobile));
  204. $update = array();
  205. $update['shop_id'] = $id;
  206. $update['name'] = $truename;
  207. $update['mobile'] = $mobile;
  208. if ($member) {
  209. $update['where_id'] = $member['id'];
  210. Dever::db('shop/member')->update($update);
  211. } else {
  212. Dever::db('shop/member')->insert($update);
  213. }
  214. }
  215. }
  216. private function updateParam()
  217. {
  218. }
  219. /**
  220. * 更新商品信息
  221. *
  222. * @return mixed
  223. */
  224. public function goodsUpdate($id, $name, $data)
  225. {
  226. $update = array();
  227. $state = Dever::param('state', $data);
  228. if ($state) {
  229. Dever::config('base')->after = true;
  230. $info = Dever::db('shop/goods')->one($id);
  231. $shop_id = $info['shop_id'];
  232. $shop = Dever::db('shop/info')->one($shop_id);
  233. if ($shop && $shop['goods']) {
  234. $goods = Dever::json_decode($shop['goods']);
  235. if (isset($goods['level_' . $info['category_id']]['value']['id_' . $info['goods_id']])) {
  236. if ($state == 2) {
  237. unset($goods['level_' . $info['category_id']]['value']['id_' . $info['goods_id']]);
  238. }
  239. if (count($goods['level_' . $info['category_id']]['value']) <= 0) {
  240. unset($goods['level_' . $info['category_id']]);
  241. }
  242. } elseif ($state == 1) {
  243. $goods_info = Dever::db('goods/info')->one($info['goods_id']);
  244. $cate = Dever::load('category/api')->string($info['category_id']);
  245. $goods['level_' . $info['category_id']]['id'] = $info['category_id'];
  246. $goods['level_' . $info['category_id']]['name'] = $cate;
  247. $goods['level_' . $info['category_id']]['value']['id_' . $info['goods_id']] = array
  248. (
  249. 'id' => $info['goods_id'],
  250. 'name' => $goods_info['name'],
  251. 'state' => 1,
  252. );
  253. }
  254. $set['goods'] = Dever::json_encode($goods);
  255. $set['where_id'] = $shop_id;
  256. Dever::db('shop/info')->update($set);
  257. }
  258. }
  259. }
  260. /**
  261. * 更新库存信息
  262. *
  263. * @return mixed
  264. */
  265. public function skuUpdate($id, $name, $data)
  266. {
  267. $update = array();
  268. $add_num = Dever::param('add_num', $data);
  269. if ($add_num) {
  270. $state = Dever::db('shop/goods_sku')->updateTotal(array('where_id' => $id, 'total_num' => $add_num));
  271. if ($state) {
  272. $state = Dever::db('shop/goods_sku')->update(array('where_id' => $id, 'add_num' => 0));
  273. $info = Dever::db('shop/goods_sku')->one($id);
  274. $goods = Dever::db('shop/goods')->one(array('goods_id' => $info['goods_id'], 'shop_id' => $info['shop_id']));
  275. if ($goods) {
  276. Dever::db('shop/goods')->update(array('where_id' => $goods['id'], 'total_num' => $info['total_num'], 'add_num' => 0));
  277. }
  278. if ($add_num < 0) {
  279. # 记录出库日志
  280. } else {
  281. # 记录入库日志
  282. }
  283. }
  284. }
  285. }
  286. # 获取供货商信息
  287. public function buyInfo($type = '', $type_id = '')
  288. {
  289. if ($type == 1) {
  290. $type_info = Dever::db('shop/info')->one($type_id);
  291. return $type_info['name'] . '('.$type_info['mobile'].')';
  292. } elseif ($type == 2) {
  293. $type_info = Dever::db('store/info')->one($type_id);
  294. return $type_info['name'] . '('.$type_info['mobile'].')';
  295. } elseif ($type == 3) {
  296. $type_info = Dever::db('factory/info')->one($type_id);
  297. return $type_info['name'] . '('.$type_info['mobile'].')';
  298. } else {
  299. return '无';
  300. }
  301. }
  302. /**
  303. * 更新信息
  304. *
  305. * @return mixed
  306. */
  307. public function buyOrderPs($id, $name, $data)
  308. {
  309. $order_id = Dever::param('order_id', $data);
  310. if ($order_id) {
  311. $update['where_id'] = $order_id;
  312. $update['set_status'] = 4;
  313. Dever::db('shop/buy_order')->update($update);
  314. }
  315. }
  316. # 获取门店
  317. public function search_api()
  318. {
  319. return Dever::search('shop/info');
  320. }
  321. }