My.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. <?php
  2. namespace Mshop\Src;
  3. use Dever;
  4. use Mshop\Lib\Core;
  5. class My extends Core
  6. {
  7. public function home()
  8. {
  9. $config = Dever::db('main/manage_config')->find();
  10. $this->data['config'] = $config;
  11. $this->data['phone'] = $config['phone'];
  12. $this->data['user'] = $this->user;
  13. $this->data['shop'] = $this->shop;
  14. $this->data['date'] = date('Y-m-d');
  15. $where['mobile'] = $this->user['mobile'];
  16. $user = Dever::db('shop/member')->select($where);
  17. if ($user) {
  18. $this->data['other_shop'] = array();
  19. foreach ($user as $k => $v) {
  20. if ($v['shop_id'] != $this->shop_id) {
  21. $shop = Dever::db('shop/info')->getOne($v['shop_id']);
  22. if ($shop) {
  23. $this->data['other_shop'][] = $shop;
  24. }
  25. }
  26. }
  27. }
  28. return $this->data;
  29. }
  30. public function getEdit()
  31. {
  32. $this->data['user'] = $this->user;
  33. $this->data['shop'] = $this->shop;
  34. return $this->data;
  35. }
  36. # 修改门店资料
  37. public function edit()
  38. {
  39. $data = array();
  40. $name = Dever::input('name');
  41. if ($name) {
  42. $data['name'] = $name;
  43. }
  44. $lng = Dever::input('lng');
  45. if ($lng) {
  46. $data['lng'] = $lng;
  47. }
  48. $lat = Dever::input('lat');
  49. if ($lat) {
  50. $data['lat'] = $lat;
  51. }
  52. $address = Dever::input('address');
  53. if ($address) {
  54. $data['address'] = $address;
  55. }
  56. $truename = Dever::input('truename');
  57. if ($truename) {
  58. $data['truename'] = $name;
  59. }
  60. $mobile = Dever::input('mobile');
  61. if ($mobile) {
  62. $data['mobile'] = $mobile;
  63. }
  64. $open = Dever::input('open');
  65. if ($open) {
  66. $data['open'] = $open;
  67. }
  68. $method = Dever::input('method');
  69. if ($method) {
  70. $data['method'] = $method;
  71. }
  72. $worktime = Dever::input('worktime');
  73. if ($worktime) {
  74. $data['worktime'] = $worktime;
  75. }
  76. if ($data) {
  77. $data['where_id'] = $this->shop_id;
  78. Dever::db('shop/info')->update($data);
  79. }
  80. return 'ok';
  81. }
  82. # 员工列表
  83. public function getUser()
  84. {
  85. $where['shop_id'] = $this->shop_id;
  86. $this->data['user'] = Dever::db('shop/member')->select_page($where);
  87. $role = Dever::db('shop/member')->config['role'];
  88. foreach ($this->data['user'] as $k => $v) {
  89. $v['role_name'] = array();
  90. $v['role'] = explode(',', $v['role_id']);
  91. foreach ($role as $k1 => $v1) {
  92. if (in_array($k1, $v['role'])) {
  93. $v['role_name'][] = $v1;
  94. }
  95. }
  96. $this->data['user'][$k]['role_name'] = implode(',', $v['role_name']);
  97. }
  98. return $this->data;
  99. }
  100. # 添加员工
  101. public function getEditUser()
  102. {
  103. $this->data['role'] = Dever::db('shop/member')->config['role'];
  104. $id = Dever::input('id');
  105. if ($id) {
  106. $this->data['user'] = Dever::db('shop/member')->find($id);
  107. }
  108. return $this->data;
  109. }
  110. # 编辑员工
  111. public function upUser()
  112. {
  113. $id = Dever::input('id');
  114. $role = Dever::input('role');
  115. $avatar = Dever::input('avatar');
  116. $name = Dever::input('name');
  117. $mobile = Dever::input('mobile');
  118. if ($role) {
  119. $update['role_id'] = $role;
  120. }
  121. if ($avatar) {
  122. $update['avatar'] = $avatar;
  123. }
  124. if ($name) {
  125. $update['name'] = $name;
  126. } else {
  127. Dever::alert('姓名不能为空');
  128. }
  129. if ($mobile) {
  130. $update['mobile'] = $mobile;
  131. $check = Dever::db('shop/member')->find(array('mobile' => $mobile, 'shop_id' => $this->shop_id));
  132. if ($check && $id && $id != $check['id']) {
  133. Dever::alert('电话已存在');
  134. } elseif ($check && !$id) {
  135. Dever::alert('电话已存在');
  136. }
  137. } else {
  138. Dever::alert('电话不能为空');
  139. }
  140. $update['shop_id'] = $this->shop_id;
  141. if ($id) {
  142. $update['where_id'] = $id;
  143. Dever::db('shop/member')->update($update);
  144. } else {
  145. $id = Dever::db('shop/member')->insert($update);
  146. }
  147. return 'ok';
  148. }
  149. # 删除员工
  150. public function delUser()
  151. {
  152. $id = Dever::input('id');
  153. $info = Dever::db('shop/member')->find($id);
  154. if ($info && $info['shop_id'] == $this->shop_id) {
  155. Dever::db('shop/member')->delete($id);
  156. } else {
  157. Dever::alert('您没有权限删除');
  158. }
  159. return 'ok';
  160. }
  161. # 打印机列表
  162. public function getPrint()
  163. {
  164. $where['shop_id'] = $this->shop_id;
  165. $this->data['print'] = Dever::db('shop/print')->select($where);
  166. return $this->data;
  167. }
  168. # 添加打印机
  169. public function getEditPrint()
  170. {
  171. $id = Dever::input('id');
  172. if ($id) {
  173. $this->data['print'] = Dever::db('shop/print')->find($id);
  174. }
  175. return $this->data;
  176. }
  177. # 编辑打印机
  178. public function upPrint()
  179. {
  180. $id = Dever::input('id');
  181. $name = Dever::input('name');
  182. $number = Dever::input('number');
  183. $key = Dever::input('key');
  184. $phonenum = Dever::input('phonenum');
  185. if ($name) {
  186. $update['name'] = $name;
  187. } else {
  188. Dever::alert('名称不能为空');
  189. }
  190. if ($number) {
  191. $update['number'] = $number;
  192. } else {
  193. Dever::alert('编号不能为空');
  194. }
  195. if ($key) {
  196. $update['key'] = $key;
  197. } else {
  198. Dever::alert('识别码不能为空');
  199. }
  200. if ($phonenum) {
  201. $update['phonenum'] = $phonenum;
  202. }
  203. $update['shop_id'] = $this->shop_id;
  204. if ($id) {
  205. $update['where_id'] = $id;
  206. Dever::db('shop/print')->update($update);
  207. } else {
  208. $id = Dever::db('shop/print')->insert($update);
  209. }
  210. return 'ok';
  211. }
  212. # 删除打印机
  213. public function delPrint()
  214. {
  215. $id = Dever::input('id');
  216. $info = Dever::db('shop/print')->find($id);
  217. if ($info && $info['shop_id'] == $this->shop_id) {
  218. Dever::db('shop/print')->update(array('where_id' => $info['id'], 'state' => 2));
  219. //Dever::load('mshop/lib/feieyun')->del(array($info));
  220. } else {
  221. Dever::alert('您没有权限删除');
  222. }
  223. return 'ok';
  224. }
  225. # 营销活动 优惠券列表
  226. public function getCoupon()
  227. {
  228. $this->data['method'] = Dever::db('goods/coupon')->config['method'];
  229. $this->data['coupon'] = Dever::db('goods/coupon')->select();
  230. if ($this->data['coupon']) {
  231. $this->data['day'] = Dever::db('shop/coupon')->config['time'];
  232. foreach ($this->data['coupon'] as $k => $v) {
  233. $this->data['coupon'][$k]['check'] = 1;
  234. $check = Dever::db('shop/coupon')->find(array('shop_id' => $this->shop_id, 'coupon_id' => $v['id']));
  235. if ($check) {
  236. $this->data['coupon'][$k]['check'] = 2;
  237. $this->data['coupon'][$k]['shop'] = $check;
  238. }
  239. }
  240. }
  241. return $this->data;
  242. }
  243. # 营销活动 配置
  244. public function setCoupon()
  245. {
  246. /*
  247. $coupon_city = Dever::input('coupon_city');
  248. if ($coupon_city) {
  249. $update['where_id'] = $this->shop_id;
  250. $update['coupon_city'] = $coupon_city;
  251. Dever::db('shop/info')->update($update);
  252. }
  253. */
  254. $coupon = Dever::input('coupon');
  255. //$coupon[] = array('id' => 1, 'day' => 7, 'method' => 2, 'num' => 10);
  256. //print_r(Dever::json_encode($coupon));die;
  257. if ($coupon) {
  258. $coupon = Dever::json_decode($coupon);
  259. foreach ($coupon as $k => $v) {
  260. $info = Dever::db('shop/coupon')->find(array('shop_id' => $this->shop_id, 'coupon_id' => $v['id']));
  261. $data = array();
  262. $data['method'] = $v['method'];
  263. $data['coupon_id'] = $v['id'];
  264. $data['coupon'] = $v['method'] . ',' . $v['id'];
  265. $data['day'] = $v['day'];
  266. $data['num'] = $v['num'];
  267. if (!$info) {
  268. $data['shop_id'] = $this->shop_id;
  269. Dever::db('shop/coupon')->insert($data);
  270. } else {
  271. $data['where_id'] = $info['id'];
  272. Dever::db('shop/coupon')->update($data);
  273. }
  274. }
  275. }
  276. return $this->getCoupon();
  277. }
  278. # 获取参与活动领取的优惠券
  279. public function getActCoupon()
  280. {
  281. $act_id = Dever::input('act_id', 1);
  282. $this->data['shop_coupon'] = Dever::load('shop/lib/coupon')->getData($this->shop_id);
  283. foreach ($this->data['shop_coupon'] as $k => $v) {
  284. $this->data['shop_coupon'][$k]['info'] = Dever::db('goods/coupon')->find($v['coupon_id']);
  285. $check = Dever::db('shop/coupon_act')->find(array('shop_id' => $this->shop_id, 'shop_coupon_id' => $v['id'], 'act_id' => $act_id));
  286. $this->data['shop_coupon'][$k]['check'] = 1;
  287. if ($check) {
  288. $this->data['shop_coupon'][$k]['act_coupon'] = $check;
  289. $this->data['shop_coupon'][$k]['check'] = 2;
  290. }
  291. }
  292. return $this->data;
  293. }
  294. # 采购对账单管理
  295. public function stat_month()
  296. {
  297. $type = Dever::input('type', 'shop');
  298. $table = 'cash/' . $type;
  299. $this->data['config'] = Dever::db('main/manage_config')->find();
  300. $where['shop_id'] = $this->shop_id;
  301. $shop = Dever::db('shop/info')->find($this->shop_id);
  302. $stat_type = Dever::db($table)->config['config_type'];
  303. $status = Dever::db($table)->config['config_status'];
  304. $month = Dever::input('month');
  305. if ($month) {
  306. Dever::setInput('day', $month);
  307. if ($stat_type == 1) {
  308. list($where['start'], $where['end']) = Dever::month();
  309. } else {
  310. list($where['start'], $where['end']) = Dever::week();
  311. }
  312. }
  313. $this->data['data'] = Dever::db($table)->getAll($where);
  314. if ($this->data['data']) {
  315. foreach ($this->data['data'] as $k => $v) {
  316. $this->data['data'][$k]['name'] = Dever::load('cash/lib/set')->statDate($stat_type, $v['day']);
  317. $v['day'] = date('Y-m-d', $v['day']);
  318. Dever::setInput('day', $v['day']);
  319. if ($stat_type == 1) {
  320. list($this->data['data'][$k]['start'], $this->data['data'][$k]['end']) = Dever::month();
  321. } elseif ($stat_type == 2) {
  322. list($this->data['data'][$k]['start'], $this->data['data'][$k]['end']) = Dever::week();
  323. } else {
  324. list($this->data['data'][$k]['start'], $this->data['data'][$k]['end']) = Dever::day();
  325. }
  326. $this->data['data'][$k]['start'] = date('Y-m-d', $this->data['data'][$k]['start']);
  327. $this->data['data'][$k]['end'] = date('Y-m-d', $this->data['data'][$k]['end']);
  328. $this->data['data'][$k]['status_name'] = $status[$v['shop_status']];
  329. }
  330. }
  331. return $this->data;
  332. }
  333. # 确认对账
  334. public function set_stat_month()
  335. {
  336. $id = Dever::input('id');
  337. $type = Dever::input('type', 'shop');
  338. $table = 'cash/' . $type;
  339. $where['id'] = $id;
  340. $where['shop_id'] = $this->shop_id;
  341. $info = Dever::db($table)->find($where);
  342. if (!$info) {
  343. Dever::alert('账单不存在');
  344. }
  345. if ($info) {
  346. Dever::db($table)->update(array('where_id' => $id, 'shop_status' => 2));
  347. }
  348. return $this->stat_month();
  349. }
  350. # 查看账单详情
  351. public function stat_month_view()
  352. {
  353. $id = Dever::input('id');
  354. $type = Dever::input('type', 'shop');
  355. $table = 'cash/' . $type;
  356. $where['id'] = $id;
  357. $where['shop_id'] = $this->shop_id;
  358. $this->data['config'] = Dever::db('main/manage_config')->find();
  359. $this->data['info'] = Dever::db($table)->find($where);
  360. $stat_type = Dever::db($table)->config['config_type'];
  361. $status = Dever::db($table)->config['config_status'];
  362. if (!$this->data['info']) {
  363. Dever::alert('账单不存在');
  364. }
  365. $start = $end = '';
  366. $this->data['info']['name'] = Dever::load('cash/lib/set')->statDate($stat_type, $this->data['info']['day']);
  367. $this->data['info']['day'] = date('Y-m-d', $this->data['info']['day']);
  368. Dever::setInput('day', $this->data['info']['day']);
  369. if ($stat_type == 1) {
  370. list($this->data['info']['start'], $this->data['info']['end']) = Dever::month();
  371. } elseif ($stat_type == 2) {
  372. list($this->data['info']['start'], $this->data['info']['end']) = Dever::week();
  373. } else {
  374. list($this->data['info']['start'], $this->data['info']['end']) = Dever::day();
  375. }
  376. $start = $this->data['info']['start'];
  377. $end = $this->data['info']['end'];
  378. $this->data['info']['start'] = date('Y-m-d', $this->data['info']['start']);
  379. $this->data['info']['end'] = date('Y-m-d', $this->data['info']['end']);
  380. $this->data['info']['status_name'] = $status[$this->data['info']['shop_status']];
  381. if ($type == 'shop_sell') {
  382. $this->data['info']['cash_name'] = '未返还门店账户';
  383. if ($this->data['info']['status'] == 2) {
  384. $this->data['info']['cash_name'] = '已返还门店账户';
  385. }
  386. }
  387. $where = array();
  388. $where['type'] = 1;
  389. $where['type_id'] = $this->shop_id;
  390. $where['start'] = $start;
  391. $where['end'] = $end;
  392. $where['status'] = 2;
  393. if ($type == 'shop_sell') {
  394. $where['pay_type'] = '2,3';
  395. } else {
  396. $where['pay_type'] = 1;
  397. }
  398. $this->data['data'] = Dever::db('cash/order')->getAll($where);
  399. if ($this->data['data']) {
  400. foreach ($this->data['data'] as $k => $v) {
  401. $this->data['data'][$k]['status_name'] = '已入账';
  402. $this->data['data'][$k]['cdate'] = date('Y-m-d H:i', $v['cdate']);
  403. }
  404. }
  405. return $this->data;
  406. }
  407. # 查看账单详情
  408. public function stat_month_excel()
  409. {
  410. $data = $this->stat_month_view();
  411. $file = $data['info']['name'] . '对账单';
  412. $header = $body = array();
  413. $header = array
  414. (
  415. 'top' => array
  416. (
  417. $file . ' ' . $data['info']['status_name'] . ' 对账金额¥' . $data['info']['cash'],
  418. ),
  419. '单号',
  420. '时间',
  421. '金额',
  422. '状态'
  423. );
  424. if ($data['data']) {
  425. $body = array();
  426. foreach ($data['data'] as $k => $v) {
  427. $body[$k][0] = $v['order_num'];
  428. $body[$k][1] = $v['cdate'];
  429. $body[$k][2] = $v['cash'];
  430. $body[$k][3] = $v['status_name'];
  431. }
  432. }
  433. Dever::excelExport($body, $header, $file);
  434. }
  435. # 门店物料
  436. public function info()
  437. {
  438. $config = Dever::db('main/manage_config')->find();
  439. $this->data['file'] = $config['file'];
  440. $param['project'] = 1;
  441. $param['width'] = Dever::input('w', 150);
  442. $param['path'] = 'pages/app/shop/shop';
  443. $param['send'] = $this->shop_id;
  444. $this->data['ercode'] = Dever::load('wechat_applet/code')->get($param);
  445. return $this->data;
  446. }
  447. # 根据商品条形码编号获取商品
  448. public function getGoods()
  449. {
  450. return Dever::load('goods/lib/info')->getGoodsByCode($this->shop_id, 1, true);
  451. }
  452. #资金账户列表
  453. public function record_list(){
  454. $shop_id = Dever::input('shop_id');
  455. $month = Dever::input('month');
  456. $shop = Dever::db('shop/info')->find($shop_id);
  457. $data = array();
  458. $data['price'] = sprintf("%01.2f", $shop['price']);
  459. if ($month) {
  460. $start = $month . '-01 00:00:00';
  461. $end = date('Y-m-d', strtotime("$start +1 month -1 day"));
  462. $where['start'] = Dever::maketime($start);
  463. $where['end'] = Dever::maketime($end . ' 23:59:59');
  464. }
  465. $where['shop_id'] = $shop_id;
  466. $where['state'] = 1;
  467. $data['list'] = Dever::db('shop/record')->getAll($where);
  468. foreach($data['list'] as $k=>$v){
  469. /*
  470. if($v['type'] == 1 || $v['type'] == 3 || $v['type'] == 6 || $v['type'] == 7 || $v['type'] == 8){
  471. $data['list'][$k]['price'] = '+'.$v['price'];
  472. }else{
  473. $data['list'][$k]['price'] = $v['price'];
  474. }
  475. */
  476. if ($v['price'] > 0) {
  477. $data['list'][$k]['price'] = '+'.$v['price'];
  478. }
  479. $data['list'][$k]['cdate'] = date('Y.m.d H:i',$v['cdate']);
  480. $typeconfig = Dever::db('shop/record')->config['config_type'];
  481. $data['list'][$k]['type_name'] = Dever::status($typeconfig,$v['type']);
  482. $config = Dever::db('shop/record')->config['config_status'];
  483. $data['list'][$k]['status_name'] = Dever::status($config,$v['status']);
  484. }
  485. $data['fund'] = Dever::db('main/manage_config')->getFund(array('state'=>1));
  486. return $data;
  487. }
  488. #资金账户详情页
  489. public function record_desc(){
  490. $id = Dever::input('id');
  491. $data = Dever::db('shop/record')->find($id);
  492. /*
  493. if($data['type'] == 1 || $data['type'] == 3 || $data['type'] == 6 || $data['type'] == 7 || $data['type'] == 8){
  494. $data['price'] = '+'.$data['price'];
  495. }else{
  496. $data['price'] = $data['price'];
  497. }*/
  498. if ($data['price'] > 0) {
  499. $data['price'] = '+'.$data['price'];
  500. }
  501. $typeconfig = Dever::db('shop/record')->config['config_type'];
  502. $data['type_name'] = Dever::status($typeconfig,$data['type']);
  503. $config = Dever::db('shop/record')->config['config_status'];
  504. $data['status_name'] = Dever::status($config,$data['status']);
  505. $data['cdate'] = date('Y.m.d H:i',$data['cdate']);
  506. return $data;
  507. }
  508. }