Manage.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. <?php
  2. namespace Bill\Lib;
  3. use Dever;
  4. class Manage
  5. {
  6. public function cashUpdate($id, $name, $data)
  7. {
  8. Dever::config('base')->hook = true;
  9. $mid = Dever::param('mid', $data);
  10. $cash = Dever::param('cash', $data);
  11. $desc = Dever::param('desc', $data);
  12. $type = Dever::param('type', $data);
  13. if (!$type) {
  14. $type = 10;
  15. }
  16. if ($mid && $cash && $desc && $type) {
  17. $member = Dever::db('agent/member')->find($mid);
  18. if ($member && $member['status'] == 2) {
  19. Dever::load('bill/lib/cash')->up($mid, $type, $cash, $member['role'], $id, $desc, 2);
  20. $where = array();
  21. $where['where_id'] = $mid;
  22. $where['cash'] = $cash;
  23. $where['clear'] = true;
  24. Dever::db('agent/member')->upCash($where);
  25. } else {
  26. Dever::db('bill/push_cash')->update(array('where_id' => $id, 'status' => 2));
  27. Dever::alert('代理商未审核通过,发放失败');
  28. }
  29. }
  30. }
  31. public function cashAuditUpdateStart($param, $name, $data)
  32. {
  33. $mul_type = Dever::config('base')->mul_type;
  34. if ($mul_type == 2) {
  35. $list = Dever::db('bill/cash')->select(array('status' => 1));
  36. } else {
  37. $list = explode(',', $param['where_id']);
  38. }
  39. }
  40. public function cashAuditUpdate($id, $name, $data)
  41. {
  42. Dever::config('base')->hook = true;
  43. $audit = Dever::param('audit', $data);
  44. if ($audit > 1) {
  45. $mul_type = Dever::config('base')->mul_type;
  46. if ($mul_type == 2) {
  47. $list = Dever::db('bill/cash')->select(array('status' => 1));
  48. } else {
  49. $list = explode(',', $id);
  50. }
  51. foreach ($list as $k => $v) {
  52. if (is_array($v)) {
  53. $id = $v['id'];
  54. $info = Dever::db('bill/cash')->find(array('id' => $id, 'clear' => true));
  55. } else {
  56. $id = $v;
  57. $info = Dever::db('bill/cash')->find(array('id' => $id, 'clear' => true));
  58. }
  59. if ($info['status'] != 1) {
  60. continue;
  61. }
  62. #已审核
  63. if ($audit == 2) {
  64. Dever::db('bill/cash')->update(array('where_id' => $id, 'status' => 2, 'operdate' => time()));
  65. $info = Dever::db('bill/cash')->find($id);
  66. if ($info && $info['type'] <= 10) {
  67. $where['where_id'] = $info['mid'];
  68. $where['cash'] = $info['cash'];
  69. Dever::db('agent/member')->upCash($where);
  70. }elseif ($info && $info['type'] == 11) {
  71. $tixian = Dever::db('bill/tixian')->find($info['type_id']);
  72. $where['where_id'] = $tixian['id'];
  73. $where['status'] = 1;
  74. $admin = Dever::load('manage/auth.data');
  75. $where['audit_admin'] = $admin['id'];
  76. Dever::db('bill/tixian')->update($where);
  77. }
  78. } else {
  79. #作废
  80. Dever::db('bill/cash')->update(array('where_id' => $id, 'status' => 3, 'operdate' => time()));
  81. $info = Dever::db('bill/cash')->find($id);
  82. if ($info && $info['type'] == 11) {
  83. $tixian = Dever::db('bill/tixian')->find($info['type_id']);
  84. $where['where_id'] = $info['mid'];
  85. $where['cash'] = -1*$tixian['ycash'];
  86. Dever::db('agent/member')->upCash($where);
  87. $update['where_id'] = $tixian['id'];
  88. $update['status'] = 3;
  89. $admin = Dever::load('manage/auth.data');
  90. $update['audit_admin'] = $admin['id'];
  91. Dever::db('bill/tixian')->update($update);
  92. }
  93. }
  94. }
  95. }
  96. }
  97. public function tixianAuditUpdate($id, $name, $data)
  98. {
  99. Dever::config('base')->hook = true;
  100. $audit = Dever::param('audit', $data);
  101. $desc = Dever::param('audit_desc', $data);
  102. if ($audit > 1) {
  103. $mul_type = Dever::config('base')->mul_type;
  104. if ($mul_type == 2) {
  105. $list = Dever::db('bill/tixian')->select(array('status' => 1));
  106. } else {
  107. $list = explode(',', $id);
  108. }
  109. foreach ($list as $k => $v) {
  110. if (is_array($v)) {
  111. $id = $v['id'];
  112. $tixian = Dever::db('bill/tixian')->find(array('id' => $id, 'clear' => true));
  113. } else {
  114. $id = $v;
  115. $tixian = Dever::db('bill/tixian')->find(array('id' => $id, 'clear' => true));
  116. }
  117. if (!$tixian) {
  118. continue;
  119. }
  120. if ($tixian['status'] != 1) {
  121. continue;
  122. }
  123. if ($tixian['type'] == 1) {
  124. $info = Dever::db('bill/cash')->find(array('type' => 11, 'type_id' => $id));
  125. $table = 'bill/cash';
  126. } elseif ($tixian['type'] == 2) {
  127. $info = Dever::db('shop/record')->find(array('type' => 2, 'type_id' => $id));
  128. $table = 'shop/record';
  129. } elseif ($tixian['type'] == 3) {
  130. $info = Dever::db('shop/user_money')->find(array('type' => 11, 'type_id' => $id));
  131. $table = 'shop/user_money';
  132. }
  133. if (!$info) {
  134. continue;
  135. }
  136. if ($audit == 2) {
  137. $admin = Dever::load('manage/auth.data');
  138. $where['audit_admin'] = $admin['id'];
  139. Dever::db('bill/tixian')->update(array('where_id' => $id, 'status' => 2, 'audit_admin' => $where['audit_admin'],'operdate' => time()));
  140. if ($info && $info['status'] == 1) {
  141. Dever::db($table)->update(array('where_id' => $id, 'status' => 2, 'operdate' => time()));
  142. }
  143. # 通知短信
  144. /*
  145. if (Dever::project('sms')) {
  146. $member = Dever::db('agent/member')->find($info['mid']);
  147. Dever::load('sms/api')->send('daili_tixian_yes', $member['mobile'], array('name' => $member['name']));
  148. }
  149. */
  150. } else {
  151. $admin = Dever::load('manage/auth.data');
  152. $where['audit_admin'] = $admin['id'];
  153. Dever::db('bill/tixian')->update(array('where_id' => $id, 'status' => 3, 'audit_admin' => $where['audit_admin'],'operdate' => time()));
  154. $w = array();
  155. if ($tixian['type'] == 1) {
  156. $w['where_id'] = $info['mid'];
  157. $w['cash'] = -1*$tixian['ycash'];
  158. $w['clear'] = true;
  159. Dever::db('agent/member')->upCash($w);
  160. } elseif ($tixian['type'] == 2) {
  161. $w['where_id'] = $info['shop_id'];
  162. $w['price'] = -1*$tixian['ycash'];
  163. $w['clear'] = true;
  164. Dever::db('shop/info')->upCash($w);
  165. Dever::db($table)->update(array('where_id' => $info['id'], 'status' => 3, 'operdate' => time()));
  166. } elseif ($tixian['type'] == 3) {
  167. $w['where_id'] = $info['uid'];
  168. $w['cash'] = -1*$tixian['ycash'];
  169. $w['clear'] = true;
  170. Dever::db('passport/user')->upCash($w);
  171. }
  172. # 通知短信
  173. /*
  174. if (Dever::project('sms')) {
  175. $member = Dever::db('agent/member')->find($info['mid']);
  176. Dever::load('sms/api')->send('daili_tixian_no', $member['mobile'], array('name' => $member['name'], 'content' => $desc));
  177. }
  178. */
  179. }
  180. }
  181. }
  182. }
  183. public function sellUpdate($id, $name, $data)
  184. {
  185. Dever::config('base')->hook = true;
  186. $mid = Dever::param('mid', $data);
  187. $num = Dever::param('num', $data);
  188. $desc = Dever::param('desc', $data);
  189. $type = Dever::param('type', $data);
  190. $cdate = Dever::param('cdate',$data);
  191. if(!$cdate){
  192. $cdate = false;
  193. } else {
  194. $cdate = Dever::maketime($cdate);
  195. }
  196. if ($mid && $num && $desc) {
  197. $member = Dever::db('agent/member')->find($mid);
  198. if ($member && $member['status'] == 2) {
  199. if ($type == 1) {
  200. Dever::load('bill/lib/sell.push_one_commit', $mid, $num, $member['role'], $id, $desc,$cdate);
  201. } else {
  202. Dever::load('bill/lib/sell.push_all_commit', $mid, $num, $member['role'], $id, $desc,$cdate);
  203. }
  204. } else {
  205. Dever::db('bill/push_sell')->update(array('where_id' => $id, 'status' => 2));
  206. Dever::alert('代理商未审核通过,发放失败');
  207. }
  208. }
  209. }
  210. # 获取新增业绩
  211. public function getSellNewNum($num, $month, $mid)
  212. {
  213. $where = array('month' => $month, 'mid' => $mid);
  214. $search = Dever::search_button();
  215. if ($search) {
  216. $where['config']['group'] = $search[0];
  217. $where['config']['col'] = str_replace('|id', '', $search[1]);
  218. }
  219. if ($num < 0) {
  220. $num = 0;
  221. }
  222. $new_num = 0;
  223. $prev = Dever::db('bill/sell_stat')->prev($where);
  224. if ($prev && $num > 0 && $prev['num'] >= 0) {
  225. $new_num = $num - $prev['num'];
  226. }
  227. return $new_num;
  228. }
  229. #提现导出
  230. public function tixian_out($data){
  231. $header = array('提现单号', '姓名', '手机号', '身份证号', '会员角色', '提现金额', '到账金额', '手续费金额', '申请时间', '审核时间', '审核状态', '发放时间','发放状态','审核人', '来源');
  232. $body = array();
  233. foreach($data as $k => $v){
  234. $member = Dever::db('agent/member')->find(array('id'=>$v['mid']));
  235. $role = Dever::db('setting/role')->find(array('id'=>$member['role']));
  236. if($v['status'] == -1){
  237. $status = '未审核待发放';
  238. $audit = '待审核';
  239. }elseif($v['status'] == 1){
  240. $status = '已审核待发放';
  241. $audit = '已审核';
  242. }elseif($v['status'] == 2){
  243. $status = '已发放';
  244. $audit = '已审核';
  245. }else{
  246. $status = '已作废';
  247. $audit = '已作废';
  248. }
  249. $cdate = date('Y-m-d H:i',$v['cdate']);
  250. if ($v['type'] == 1) {
  251. $cash = Dever::db('bill/cash')->find($v['cash_id']);
  252. } elseif ($v['type'] == 2) {
  253. $cash = Dever::db('shop/record')->find($v['cash_id']);
  254. } elseif ($v['type'] == 3) {
  255. $cash = Dever::db('shop/user_money')->find($v['cash_id']);
  256. }
  257. if ($cash['operdate']) {
  258. $adate = date('Y-m-d H:i',$cash['operdate']);
  259. } else {
  260. $adate = '-';
  261. }
  262. if ($v['operdate']) {
  263. $operdate = date('Y-m-d H:i',$v['operdate']);
  264. } else {
  265. $operdate = '-';
  266. }
  267. if($v['audit_admin']){
  268. $admin = Dever::load('manage/admin-find',$v['audit_admin']);
  269. $username = $admin['username'];
  270. }else{
  271. $username = '';
  272. }
  273. if($v['ycash'] < 0){
  274. $ycash = $v['ycash'] * (-1);
  275. }else{
  276. $ycash = $v['ycash'];
  277. }
  278. if($v['cash'] < 0){
  279. $cash = $v['cash'] * (-1);
  280. }else{
  281. $cash = $v['cash'];
  282. }
  283. $d = array
  284. (
  285. $v['order_num'],
  286. $member['name'],
  287. $member['mobile'],
  288. $member['idcard'],
  289. $role['name'],
  290. $ycash,
  291. $cash,
  292. $ycash-$cash,
  293. $cdate,
  294. $adate,
  295. $audit,
  296. $operdate,
  297. $status,
  298. $username,
  299. '',
  300. );
  301. $body[] = $d;
  302. }
  303. $file = Dever::input('excel_name');
  304. return Dever::excelExport($body, $header, $file);
  305. }
  306. #归店统计导出
  307. public function out_shop_stat($data){
  308. $header = array('月份', '门店名称','门店编号','门店联系人','联系人手机号','联系人身份证','所属代理商', '区域招商补贴', '名额外创V补贴', '补贴总金额', '采购金额','归店业绩(除创V外)','代理商数','创客数','创V数','名额外创V','名额外创V业绩', '确认状态', '发放状态');
  309. $body = array();
  310. foreach($data as $k => $v){
  311. $month = date('Y-m',$v['month'])."\t";
  312. $shop = Dever::db('shop/info')->find(array('id'=>$v['shop_id']));
  313. if ($shop['type'] != 1) {
  314. continue;
  315. }
  316. if($shop['mid'] && $shop['mid'] >0){
  317. $member = Dever::db('agent/member')->find($shop['mid']);
  318. if($member){
  319. $dl_mobile = $member['mobile'];
  320. }else{
  321. $dl_mobile = '-';
  322. }
  323. }else{
  324. $dl_mobile = '-';
  325. }
  326. $shop_truename = '';
  327. if ($shop['truename']) {
  328. $shop_truename = $shop['truename'];
  329. }
  330. $shop_mobile = '';
  331. if ($shop['mobile']) {
  332. $shop_mobile = $shop['mobile'];
  333. }
  334. $shop_idcard = '';
  335. if ($shop['idcard']) {
  336. $shop_idcard = $shop['idcard'];
  337. }
  338. $status_name = '';
  339. if ($v['status'] == 1) {
  340. $status_name = '已确认';
  341. } elseif ($v['status'] == 2) {
  342. $status_name = '未确认';
  343. }
  344. $cash_status_name = '';
  345. if ($v['cash_status'] == 1) {
  346. $cash_status_name = '已发放';
  347. } elseif ($v['cash_status'] == 2) {
  348. $cash_status_name = '未发放';
  349. }
  350. $d = array
  351. (
  352. $month,
  353. $shop['name'],
  354. $shop['sid'],
  355. $shop_truename,
  356. $shop_mobile,
  357. $shop_idcard,
  358. $dl_mobile,
  359. $v['dl_subsidy'],
  360. $v['v_subsidy'],
  361. $v['dl_subsidy'] + $v['v_subsidy'],
  362. $v['c_money'],
  363. $v['dl_money'],
  364. $v['dl_num'],
  365. $v['ck_num'],
  366. $v['v_num'],
  367. $v['out_num'],
  368. $v['out_money'],
  369. $status_name,
  370. $cash_status_name,
  371. );
  372. $body[] = $d;
  373. }
  374. $file = Dever::input('excel_name');
  375. return Dever::excelExport($body, $header, $file);
  376. }
  377. #归店列表显示
  378. public function shop_stat_api($id){
  379. $info = Dever::db('bill/shop_stat')->find($id);
  380. $shop = Dever::db('shop/info')->find($info['shop_id']);
  381. $html = $shop['name'];
  382. $html .= '<br />' .$shop['sid'];
  383. if($shop['agent_mid'] && $shop['agent_mid']>0){
  384. $member = Dever::db('agent/member')->find($shop['agent_mid']);
  385. if($member){
  386. $html .= '<br />' .$member['name'].$member['mobile'];
  387. }
  388. }
  389. return $html;
  390. }
  391. public function guidian($mid){
  392. $member = Dever::db('agent/member')->find($mid);
  393. $area = Dever::load("area/api.string", $member['area']);
  394. $data = array();
  395. $data = $member['name'].'<br/>'.$member['mobile'].'<br/>'.$area;
  396. return $data;
  397. }
  398. public function role($mid){
  399. $member = Dever::db('agent/member')->find($mid);
  400. $role = Dever::db('setting/role')->find($member['role']);
  401. $data = array();
  402. $prize_type = '';
  403. if($member['role'] == 8 && $member['prize_type'] == 1){
  404. $prize_type = '(名额外)';
  405. }elseif($member['role'] == 8 && $member['prize_type'] == 2){
  406. $prize_type = '(名额内)';
  407. }
  408. $data = $role['name'].$prize_type;
  409. return $data;
  410. }
  411. public function yeji($mid){
  412. $start = Dever::input('search_option_start_dever_time');
  413. $end = Dever::input('search_option_dever_time');
  414. $where['start'] = $start;
  415. $where['end'] = $end;
  416. $where['mid'] = $mid;
  417. $where['state'] = 1;
  418. $money = Dever::db('agent/order')->getCount($where);
  419. return $money['total'];
  420. }
  421. }