Manage.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <?php
  2. namespace Store\Lib;
  3. use Dever;
  4. class Manage
  5. {
  6. /**
  7. * 更新信息
  8. *
  9. * @return mixed
  10. */
  11. public function infoUpdate($id, $name, $data)
  12. {
  13. $update = array();
  14. $area = Dever::param('area', $data);
  15. if ($area) {
  16. $temp = is_string($area) ? explode(',', $area) : $area;
  17. $update['province'] = $temp[0];
  18. $update['city'] = $temp[1];
  19. if (isset($temp[2])) {
  20. $update['county'] = $temp[2];
  21. }
  22. }
  23. $map = Dever::param('map', $data);
  24. if ($map) {
  25. $temp = is_string($map) ? explode(',', $map) : $map;
  26. if (isset($temp[1])) {
  27. $update['lng'] = $temp[1];
  28. $update['lat'] = $temp[2];
  29. }
  30. }
  31. $goods = Dever::param('goods', $data);
  32. if ($goods) {
  33. $goods = Dever::json_decode($goods);
  34. if ($goods) {
  35. foreach ($goods as $k1 => $v1) {
  36. if ($v1['value']) {
  37. foreach ($v1['value'] as $k => $v) {
  38. if ($v['state'] == 1) {
  39. $w = array();
  40. $w['goods_id'] = $v['id'];
  41. $w['store_id'] = $id;
  42. $info = Dever::db('store/goods')->one($w);
  43. $w['category_id'] = $v1['id'];
  44. if (!$info) {
  45. Dever::db('store/goods')->insert($w);
  46. } else {
  47. $w['where_id'] = $info['id'];
  48. $w['state'] = 1;
  49. Dever::db('store/goods')->update($w);
  50. }
  51. } else {
  52. unset($goods[$k1]['value'][$k]);
  53. }
  54. }
  55. }
  56. }
  57. $update['goods'] = Dever::json_encode($goods);
  58. }
  59. }
  60. if (isset($update) && $update) {
  61. $update['where_id'] = $id;
  62. Dever::db('store/info')->update($update);
  63. }
  64. $truename = Dever::param('truename', $data);
  65. $mobile = Dever::param('mobile', $data);
  66. if ($mobile) {
  67. $member = Dever::db('store/member')->one(array('store_id' => $id, 'mobile' => $mobile));
  68. $update = array();
  69. $update['store_id'] = $id;
  70. $update['name'] = $truename;
  71. $update['mobile'] = $mobile;
  72. if ($member) {
  73. $update['where_id'] = $member['id'];
  74. Dever::db('store/member')->update($update);
  75. } else {
  76. Dever::db('store/member')->insert($update);
  77. }
  78. }
  79. }
  80. /**
  81. * 更新商品信息
  82. *
  83. * @return mixed
  84. */
  85. public function goodsUpdate($id, $name, $data)
  86. {
  87. $update = array();
  88. $state = Dever::param('state', $data);
  89. if ($state) {
  90. Dever::config('base')->after = true;
  91. $info = Dever::db('store/goods')->one($id);
  92. $store_id = $info['store_id'];
  93. $store = Dever::db('store/info')->one($store_id);
  94. if ($store && $store['goods']) {
  95. $goods = Dever::json_decode($store['goods']);
  96. if (isset($goods['level_' . $info['category_id']]['value']['id_' . $info['goods_id']])) {
  97. if ($state == 2) {
  98. unset($goods['level_' . $info['category_id']]['value']['id_' . $info['goods_id']]);
  99. }
  100. if (count($goods['level_' . $info['category_id']]['value']) <= 0) {
  101. unset($goods['level_' . $info['category_id']]);
  102. }
  103. } elseif ($state == 1) {
  104. $goods_info = Dever::db('goods/info')->one($info['goods_id']);
  105. $cate = Dever::load('category/api')->string($info['category_id']);
  106. $goods['level_' . $info['category_id']]['id'] = $info['category_id'];
  107. $goods['level_' . $info['category_id']]['name'] = $cate;
  108. $goods['level_' . $info['category_id']]['value']['id_' . $info['goods_id']] = array
  109. (
  110. 'id' => $info['goods_id'],
  111. 'name' => $goods_info['name'],
  112. 'state' => 1,
  113. );
  114. }
  115. $set['goods'] = Dever::json_encode($goods);
  116. $set['where_id'] = $store_id;
  117. Dever::db('store/info')->update($set);
  118. }
  119. }
  120. }
  121. /**
  122. * 更新库存信息
  123. *
  124. * @return mixed
  125. */
  126. public function skuUpdate($id, $name, $data)
  127. {
  128. $update = array();
  129. $add_num = Dever::param('add_num', $data);
  130. if ($add_num) {
  131. $goods_sku = Dever::db('store/goods_sku')->one($id);
  132. $state = Dever::db('store/goods_sku')->updateTotal(array('where_id' => $id, 'total_num' => $add_num));
  133. if ($state) {
  134. $state = Dever::db('store/goods_sku')->update(array('where_id' => $id, 'add_num' => 0, 'operdate' => time()));
  135. $goods = Dever::db('store/goods')->one(array('goods_id' => $goods_sku['goods_id'], 'store_id' => $goods_sku['store_id']));
  136. if ($goods) {
  137. Dever::db('store/goods')->update(array('where_id' => $goods['id'], 'total_num' => $goods_sku['total_num'], 'add_num' => 0));
  138. }
  139. $log['sid'] = $id;
  140. $log['store_id'] = $goods_sku['store_id'];
  141. $log['goods_id'] = $goods_sku['goods_id'];
  142. $log['sku_id'] = $goods_sku['sku_id'];
  143. $log['sell_num'] = $goods_sku['sell_num'];
  144. $log['total_num'] = $goods_sku['total_num'];
  145. $log['num'] = $add_num;
  146. $log['after_total_num'] = $goods_sku['total_num'] + $add_num;
  147. $log['cur_num'] = $log['total_num'] - $goods_sku['sell_num'];
  148. $log['after_cur_num'] = $log['after_total_num'] - $goods_sku['sell_num'];
  149. if ($log['cur_num'] < 0) {
  150. $log['cur_num'] = 0;
  151. }
  152. if ($log['after_cur_num'] < 0) {
  153. $log['after_cur_num'] = 0;
  154. }
  155. $log['online_num'] = Dever::load("shop/lib/manage.getGoodsTotal", 2, $goods_sku['store_id'], $goods_sku['goods_id'], $goods_sku['sku_id']);
  156. Dever::db('store/goods_log')->insert($log);
  157. }
  158. }
  159. }
  160. # 根据分类获取商品
  161. public function getInfo_api()
  162. {
  163. $where['city'] = Dever::input('city');
  164. $data = Dever::db('store/info')->select($where);
  165. return $data;
  166. }
  167. public function search_api()
  168. {
  169. return Dever::search('store/info');
  170. }
  171. # 获取仓库的商品列表
  172. public function goods_api()
  173. {
  174. $source_id = Dever::input('source_id', 1);
  175. return Dever::outDiy(Dever::load('store/lib/goods')->getSkuList($source_id));
  176. }
  177. # 获取收银台
  178. public function cashier_api()
  179. {
  180. $data = array();
  181. $data['source_id'] = Dever::input('source_id', 1);
  182. $data['host'] = Dever::url('lib/manage.cashier', 'store');
  183. $data['url'] = Dever::url('lib/manage.goods?source_id=' . $data['source_id'], 'store');
  184. $data['search'] = Dever::url('lib/manage.search?yes='.$data['source_id'].'&json=1', 'store');
  185. $data['search_store'] = Dever::url('lib/manage.search?json=1', 'store');
  186. $data['submit'] = Dever::url('lib/order.action_commit?json=1', 'store');
  187. return Dever::render('cashier', $data);
  188. }
  189. }