Member.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967
  1. <?php
  2. namespace Agent\Lib;
  3. use Dever;
  4. class Member
  5. {
  6. public function getUserNum($id)
  7. {
  8. return Dever::load("invite/api")->getChildNum($id, false);
  9. }
  10. public function getOne($id, $table = 'agent/member', $area = false, $admin_auth = false)
  11. {
  12. if ($id < 0) {
  13. return '无';
  14. }
  15. $member = Dever::db($table)->one($id);
  16. if ($member) {
  17. if (isset($member['mid'])) {
  18. $member['id'] = $member['mid'];
  19. }
  20. $member['role'] = Dever::db('setting/role')->find($member['role']);
  21. $url = Dever::url('project/database/list?project=agent&table=member_area&mid='.$member['id'].'&page_type=1&search_option_state=1&[refer]', 'manage');
  22. $member['name'] = '<a href="'.$url.'">' . $member['name'] . '</a>';
  23. $code = Dever::load("invite/api.code", $member['id']);
  24. $string = '';
  25. if ($code) {
  26. $string = '[' . $code . '] <br />';
  27. }
  28. $prize_type = '';
  29. if($member['role']['id'] == 8){
  30. if($member['prize_type'] && $member['prize_type'] == 1){
  31. $prize_type = '(名额外)';
  32. }elseif($member['prize_type'] && $member['prize_type'] == 2){
  33. $prize_type = '(名额内)';
  34. }
  35. }
  36. $string .= $member['name'] . '('.$member['id'].')' .'<br />' . $member['mobile'] . '<br />' . $member['role']['name'].$prize_type;
  37. if (!$admin_auth) {
  38. if (isset($member['level_id']) && $member['level_id'] && $member['level_id'] > 0) {
  39. $member['level'] = Dever::db('setting/level')->find($member['level_id']);
  40. $string .= '('.$member['level']['name'].')';
  41. }
  42. }
  43. if (isset($member['shop_id']) && $member['shop_id'] > 0) {
  44. $string .= ' ' . Dever::load("shop/info-one#name", $member['shop_id']);
  45. }
  46. if ($area) {
  47. $area = Dever::load("area/api.string", $member['area']);
  48. if ($area) {
  49. $string .= '<br />' . $area;
  50. }
  51. }
  52. $member['mobile'] = strip_tags($member['mobile']);
  53. $url = Dever::url('project/database/list?project=agent&table=member&search_api_parent_mid='.$member['mobile'].'&search_option_state=1&[refer]', 'manage');
  54. if (!$admin_auth) {
  55. $string .= '<br /><a href="'.$url.'">直推:'. Dever::load("invite/api")->getChildNum($member['id'], 1) . '</a>';
  56. }
  57. if ($member['source_id'] > 0) {
  58. $source = Dever::db('setting/source')->one($member['source_id']);
  59. if ($source) {
  60. $string .= '<br />来源:' . $source['name'];
  61. }
  62. }
  63. return $string;
  64. } else {
  65. return '';
  66. }
  67. }
  68. public function getInfoString($member)
  69. {
  70. $member = $this->getInfo($member);
  71. $info = '代理商信息:'.$member['name'].' '.$member['mobile'].' ' . $member['role']['name'];
  72. if ($member && isset($member['level']) && $member['level']) {
  73. $info .= '('.$member['level']['name'].')';
  74. }
  75. return $info;
  76. }
  77. public function getInfo($member)
  78. {
  79. Dever::setInput('getInfo', 1);
  80. if (is_numeric($member)) {
  81. $member = Dever::db('agent/member')->find($member);
  82. }
  83. $member['area_string'] = Dever::load("area/api.string", $member['area'], '/', true, '');
  84. $member['role'] = Dever::db('setting/role')->find($member['role']);
  85. $member['level'] = Dever::db('setting/level')->find($member['level_id']);
  86. $member['title'] = array();
  87. if($member['title_id']) {
  88. $title_id = explode(',',$member['title_id']);
  89. if ($title_id) {
  90. foreach ($title_id as $k =>$v) {
  91. $info = Dever::db('setting/title')->getTitle(array('id'=>$v));
  92. if ($info) {
  93. $title[] = $info;
  94. }
  95. }
  96. }
  97. foreach ($title as $k1 => $v1) {
  98. $t[] = $v1['name'];
  99. }
  100. if ($t) {
  101. $member['title'] = implode('、',$t);
  102. }
  103. }
  104. $member['shop'] = array();
  105. if ($member['shop_id'] && $member['shop_id'] > 0) {
  106. $member['shop'] = Dever::db('shop/info')->find($member['shop_id']);
  107. }
  108. $data = Dever::load('passport/reg')->getSign($member['id']);
  109. if ($data['signature']) {
  110. $member['signature'] = $data['signature'];
  111. }
  112. $member['birthday'] = date('Y-m-d', $member['birthday']);
  113. #是否归店
  114. $guidian = Dever::db('agent/member_shop_log')->find(array('mid'=>$member['id']));
  115. if ($guidian) {
  116. $member['guidian_status'] = 1;
  117. $member['guidian_name'] = '已归店';
  118. $member['guidian_cdate'] = date('Y-m-d H:i',$guidian['cdate']);
  119. } else {
  120. $member['guidian_status'] = 2;
  121. $member['guidian_name'] = '未归店';
  122. $member['guidian_cdate'] = '';
  123. }
  124. return $member;
  125. }
  126. /**
  127. * 检测邀请码
  128. *
  129. * @return mixed
  130. */
  131. public function checkCode()
  132. {
  133. $code = Dever::input('code');
  134. if (!$code) {
  135. Dever::alert('请输入邀请码');
  136. }
  137. $uid = Dever::load('invite/api')->getUid($code);
  138. if (!$uid) {
  139. Dever::alert('请输入正确的邀请码');
  140. }
  141. $user = Dever::db('agent/member')->find($uid);
  142. if (!$user) {
  143. Dever::alert('请输入正确的邀请码');
  144. }
  145. if ($user['status'] <= 2) {
  146. return $user;
  147. }
  148. Dever::alert('邀请人状态不正常');
  149. }
  150. /**
  151. * 验证手机号
  152. * @return mixed
  153. */
  154. public function checkMobile($mobile)
  155. {
  156. $rule = Dever::rule('mobile');
  157. if (!$mobile) {
  158. Dever::alert('手机号不能为空');
  159. }
  160. if (!preg_match($rule, $mobile)) {
  161. Dever::alert('手机号码格式错误');
  162. }
  163. return $mobile;
  164. }
  165. /**
  166. * 验证验证码
  167. * @return mixed
  168. */
  169. public function checkMcode($mobile)
  170. {
  171. $code = Dever::input('mcode');
  172. if (!$code) {
  173. Dever::alert('请输入验证码');
  174. }
  175. $code = Dever::load('passport/reg')->mcode($mobile, $code, 1);
  176. if ($mobile == '18030186059') {
  177. return;
  178. }
  179. if (!$code) {
  180. Dever::alert('验证码输入错误');
  181. }
  182. }
  183. /**
  184. * 更新余额和业绩
  185. * @return mixed
  186. */
  187. public function up($child, $mid, $order_id, $role, $type, $cash, $sell, $level_id = false, $desc = '', $group_num = 0)
  188. {
  189. $member = Dever::db('agent/member')->find(array('id' => $mid, 'clear' => true));
  190. $data['where_id'] = $mid;
  191. if ($cash) {
  192. Dever::load('bill/lib/cash')->up($mid, $type, $cash, $role, $order_id, $desc, 2);
  193. $data['cash'] = $cash;
  194. } else {
  195. $data['cash'] = 0;
  196. }
  197. Dever::load('bill/lib/sell')->up($child, $mid, $type, $sell, $role, $order_id, $desc);
  198. $data['upcol'] = $sell;
  199. if ($level_id) {
  200. $data['level_id'] = $level_id;
  201. }
  202. //$method = 'upGroupSell';
  203. if ($type == 1) {
  204. $method = 'upSell';
  205. } else {
  206. $method = 'upGroupSell';
  207. }
  208. $data['clear'] = true;
  209. Dever::db('agent/member')->$method($data);
  210. if ($level_id && $level_id != $member['level_id']) {
  211. Dever::load('agent/lib/level_log')->up($mid, $order_id, $member['level_id'], $level_id, $sell, $member['group_sell'] + $sell, $group_num);
  212. }
  213. }
  214. /**
  215. * 查看详情
  216. * @return mixed
  217. */
  218. public function show()
  219. {
  220. $mid = Dever::input('mid');
  221. $member = Dever::db('agent/member')->one($mid);
  222. $admin = Dever::load('manage/auth.info');
  223. $admin_auth = false;
  224. if ($admin && $admin['role'] == 24){
  225. $admin_auth = $admin['role'];
  226. }
  227. $config_type = Dever::db('agent/member')->config['config_type'];
  228. $config_status = Dever::db('agent/member')->config['config_status'];
  229. $result['代理商信息'] = $this->getShowInfo($member,$admin_auth);
  230. if ($member['parent_mid'] && $member['parent_mid'] > 0) {
  231. $parent = Dever::db('agent/member')->one($member['parent_mid']);
  232. if ($parent) {
  233. $result['推荐人信息'] = $this->getShowInfo($parent,$admin_auth);
  234. }
  235. }
  236. $idcard_pic = '<a href="'.$member['idcard_front'].'" target="_blank"><img src="'.$member['idcard_front'].'" width="100" /></a>';
  237. if ($member['idcard_back']) {
  238. $idcard_pic .= '&nbsp;&nbsp;<a href="'.$member['idcard_back'].'" target="_blank"><img src="'.$member['idcard_back'].'" width="100" /></a>';
  239. }
  240. $member_name = $member['name'];
  241. $member_number = $member['idcard'];
  242. $result['认证信息'] = array
  243. (
  244. 'type' => 'user',
  245. 'content' => array
  246. (
  247. array('类型', $config_type[$member['type']]),
  248. array('姓名', $member_name),
  249. array('身份证号', $member_number),
  250. ),
  251. );
  252. if ($member['type'] == 2) {
  253. $company_pic = '<a href="'.$member['company_pic'].'" target="_blank"><img src="'.$member['company_pic'].'" width="100" /></a>';
  254. $member_name = $member['company_name'];
  255. $member_number = $member['company_number'];
  256. $result['认证信息']['content'][] = array('企业名称', $member_name);
  257. $result['认证信息']['content'][] = array('营业执照', $member_number);
  258. $result['认证信息']['content'][] = array('营业执照照片', $company_pic);
  259. }
  260. $result['认证信息']['content'][] = array('身份证照片', $idcard_pic);
  261. $button = array();
  262. if (Dever::load('manage/auth')->checkFunc('agent.member', 'edit', '修改基础资料')) {
  263. $button[0]['btn'][] = array
  264. (
  265. 'type' => 'edit',
  266. 'link' => Dever::url('project/database/update?project=agent&table=member&where_id='.$member['id'].'&status=1&col=name,email,area,role,level_id,is_area', 'manage'),
  267. 'name' => '修改基础资料',
  268. );
  269. }
  270. if (Dever::load('manage/auth')->checkFunc('agent.member', 'editTitle', '修改头衔')) {
  271. $button[0]['btn'][] = array
  272. (
  273. 'type' => 'edit',
  274. 'link' => Dever::url('project/database/update?project=agent&table=member&where_id='.$member['id'].'&status=1&col=title_id,state', 'manage'),
  275. 'name' => '修改头衔',
  276. );
  277. }
  278. if (Dever::load('manage/auth')->checkFunc('agent.member', 'editPassport', '修改密码')) {
  279. $button[0]['btn'][] = array
  280. (
  281. 'type' => 'edit',
  282. 'link' => Dever::url('project/database/update?project=agent&table=member&where_id='.$member['id'].'&status=1&col=password', 'manage'),
  283. 'name' => '修改密码',
  284. );
  285. }
  286. if (Dever::load('manage/auth')->checkFunc('agent.member','sport','修改认证资料')) {
  287. $button[0]['btn'][] = array
  288. (
  289. 'type' => 'edit',
  290. 'link' => Dever::url('project/database/update?project=agent&table=member&where_id='.$member['id'].'&status=1&col=type,idcard,idcard_front,idcard_back,company_name,company_pic,company_number', 'manage'),
  291. 'name' => '修改认证资料',
  292. );
  293. }
  294. if (Dever::load('manage/auth')->checkFunc('agent.member', 'editShop', '修改门店')) {
  295. $button[0]['btn'][] = array
  296. (
  297. 'type' => 'edit',
  298. 'link' => Dever::url('project/database/update?project=agent&table=member&where_id='.$member['id'].'&status=1&col=shop_id', 'manage'),
  299. 'name' => '修改门店',
  300. );
  301. }
  302. if (Dever::load('manage/auth')->checkFunc('agent.member', 'editguidianShop', '门店是否可以修改')) {
  303. $button[0]['btn'][] = array
  304. (
  305. 'type' => 'edit',
  306. 'link' => Dever::url('project/database/update?project=agent&table=member&where_id='.$member['id'].'&status=1&col=is_shop', 'manage'),
  307. 'name' => '门店是否可以修改',
  308. );
  309. }
  310. if (Dever::load('manage/auth')->checkFunc('agent.member', 'editMobile', '修改手机号')) {
  311. $button[0]['btn'][] = array
  312. (
  313. 'type' => 'edit',
  314. 'link' => Dever::url('project/database/update?project=agent&table=member&where_id='.$member['id'].'&status=1&col=mobile', 'manage'),
  315. 'name' => '修改手机号',
  316. );
  317. }
  318. /*
  319. $button[] = array
  320. (
  321. 'type' => 'edit',
  322. 'link' => Dever::url('project/database/update?project=agent&table=member&where_id='.$member['id'].'&status=1&col=shop_id', 'manage'),
  323. 'name' => '修改归属门店',
  324. );
  325. */
  326. $url = '';
  327. if ($member['status'] == 5) {
  328. $button[0]['btn'][] = array
  329. (
  330. 'type' => 'action',
  331. 'link' => Dever::url('lib/member.setStatus?id=' . $member['id'] . '&value=2', 'agent'),
  332. 'name' => '恢复账号',
  333. 'auth' => array('agent.member', 'bun', '禁用账号'),
  334. );
  335. } elseif ($member['status'] == 2) {
  336. $button[0]['btn'][] = array
  337. (
  338. 'type' => 'action',
  339. 'link' => Dever::url('lib/member.setStatus?id=' . $member['id'] . '&value=5', 'agent'),
  340. 'name' => '禁用账号',
  341. 'auth' => array('agent.member', 'bun', '禁用账号'),
  342. );
  343. }
  344. $button[0]['btn'][] = array
  345. (
  346. 'type' => 'link',
  347. 'link' => Dever::url('project/database/list?project=agent&table=order&search_api_mid='.$member['mobile'].'&[refer]', 'manage'),
  348. 'name' => '代理订单',
  349. 'auth' => array('agent.member', 'dailidingdan', '代理订单'),
  350. );
  351. $button[0]['btn'][] = array
  352. (
  353. 'type' => 'link',
  354. 'link' => Dever::url('project/database/list?project=agent&table=order&search_api_parent_mid='.$member['mobile'].'&[refer]', 'manage'),
  355. 'name' => '直推代理订单',
  356. 'auth' => array('agent.member', 'ztdailidingdan', '直推代理订单'),
  357. );
  358. $button[0]['btn'][] = array
  359. (
  360. 'type' => 'link',
  361. 'link' => Dever::url('project/database/list?project=agent&table=member_level_log&search_api_mid='.$member['mobile'].'&[refer]', 'manage'),
  362. 'name' => '升级日志',
  363. 'auth' => array('agent.member', 'sjlog', '升级日志'),
  364. );
  365. $button[1]['btn'][] = array
  366. (
  367. 'type' => 'edit',
  368. 'link' => Dever::url('project/database/update?project=bill&table=push_cash&search_option_mid='.$member['id'], 'manage'),
  369. 'name' => '发放资金',
  370. 'auth' => array('agent.member', 'edit1'),
  371. );
  372. $button[1]['btn'][] = array
  373. (
  374. 'type' => 'edit',
  375. 'link' => Dever::url('project/database/update?project=bill&table=push_sell&search_option_mid='.$member['id'], 'manage'),
  376. 'name' => '发放业绩',
  377. 'auth' => array('agent.member', 'edit2'),
  378. );
  379. $button[1]['btn'][] = array
  380. (
  381. 'type' => 'link',
  382. 'link' => Dever::url('project/database/list?project=bill&table=cash&search_api_mid='.$member['mobile'].'&search_option_state=1&[refer]', 'manage'),
  383. 'name' => '资金账户',
  384. 'auth' => array('agent.member', 'zjaccount', '资金账户'),
  385. );
  386. $button[1]['btn'][] = array
  387. (
  388. 'type' => 'link',
  389. 'link' => Dever::url('project/database/list?project=bill&table=sell&search_api_mid='.$member['mobile'].'&search_option_state=1&[refer]', 'manage'),
  390. 'name' => '业绩流水',
  391. 'auth' => array('agent.member', 'yjls', '业绩流水'),
  392. );
  393. $button[1]['btn'][] = array
  394. (
  395. 'type' => 'link',
  396. 'link' => Dever::url('project/database/list?project=agent&table=member_goods&search_option_state=1&search_api_mid='.$member['mobile'].'&[refer]', 'manage'),
  397. 'name' => '代理商权益',
  398. 'auth' => array('agent.member', 'dailisqy', '代理商权益'),
  399. );
  400. $button[1]['btn'][] = array
  401. (
  402. 'type' => 'link',
  403. 'link' => Dever::url('project/database/list?project=agent&table=dh_order&search_option_state=1&search_api_mid='.$member['mobile'].'&[refer]', 'manage'),
  404. 'name' => '权益订单',
  405. 'auth' => array('agent.member', 'qydingdan', '权益订单'),
  406. );
  407. $order = Dever::db('agent/order')->find(array('mid' => $member['id'], 'order_type' => 1));
  408. if ($order) {
  409. $agreement = Dever::db('agent/member_agreement')->getData(array('order_id' => $order['id']));
  410. if (!$agreement) {
  411. $button[2]['btn'][] = array
  412. (
  413. 'type' => 'action',
  414. 'link' => Dever::url('lib/manage.createAgreement?json=1&order_id='.$order['id'], 'agent'),
  415. 'name' => '生成代理合同',
  416. 'auth' => array('agent.member', 'createAgreement1'),
  417. );
  418. }
  419. }
  420. $button[2]['btn'][] = array
  421. (
  422. 'type' => 'link',
  423. 'link' => Dever::url('project/database/list?project=agent&table=member_agreement&search_option_state=1&search_api_mid='.$member['mobile'].'&[refer]', 'manage'),
  424. 'name' => '代理商合同',
  425. 'auth' => array('agent.member', 'dailisht', '代理商合同'),
  426. );
  427. $button[2]['btn'][] = array
  428. (
  429. 'type' => 'link',
  430. 'link' => Dever::url('project/database/list?project=agent&table=member&search_option_state=1&search_api_parent_mid='.$member['mobile'].'&[refer]', 'manage'),
  431. 'name' => '查看直推团队',
  432. 'auth' => array('agent.member', 'ckztgroup', '查看直推团队'),
  433. );
  434. /*
  435. $button[2]['btn'][] = array
  436. (
  437. 'type' => 'edit',
  438. 'link' => Dever::url('lib/member.setStatus?id=' . $member['id'] . '&value=5', 'agent'),
  439. 'name' => '查看邀请关系',
  440. );
  441. */
  442. $furl = '';
  443. $button[2]['btn'][] = array
  444. (
  445. 'type' => 'edit',
  446. 'link' => Dever::url('project/database/update?project=agent&table=member_parent&mid='.$member['id'], 'manage'),
  447. 'name' => '设置直推上级',
  448. 'auth' => array('agent.member', 'set'),
  449. 'log' => false,
  450. );
  451. $table = 'template';
  452. $res = Dever::load('sms/api')->getTable($table);
  453. $button[2]['btn'][] = array
  454. (
  455. 'type' => 'edit',
  456. 'link' => Dever::url($res.'&search_option_state=1&search_option_type=daili_reg_yes,daili_reg_no,daili_goods_no,daili_tixian_yes,daili_tixian_no,daili_hetong_no&search_option_name='.$member['name'].'&search_option_mobile='.$member['mobile'], 'manage'),
  457. 'name' => '发送短信',
  458. 'auth' => array('agent.member', 'setmessage'),
  459. 'log' => false,
  460. );
  461. /*
  462. if (Dever::load('manage/auth')->checkFunc('agent.member', 'edit6', '查看关系图谱')) {
  463. $button[2]['btn'][] = array
  464. (
  465. 'type' => 'link',
  466. 'link' => Dever::url('lib/manage.relation?mid='.$member['id'].'&[refer].manage', 'agent'),
  467. 'name' => '查看关系图谱',
  468. );
  469. }
  470. */
  471. $jump = Dever::input('jump');
  472. if (!$jump) {
  473. $head_btn[] = array
  474. (
  475. 'type' => 'link',
  476. 'link' => 'refer',
  477. 'name' => '返回上一页',
  478. );
  479. $head = array
  480. (
  481. 'name' => '基本信息',
  482. 'btn' => $head_btn,
  483. );
  484. } else {
  485. $head = array
  486. (
  487. 'name' => '基本信息',
  488. 'btn' => '',
  489. );
  490. }
  491. $foot = $button;
  492. $html = Dever::show($head, $result, $foot, false, 'dls-user-box');
  493. return $html;
  494. }
  495. public function getShowInfo($member,$admin_auth=false)
  496. {
  497. $role = Dever::db('setting/role')->one($member['role']);
  498. $level = Dever::db('setting/level')->one($member['level_id']);
  499. $area = Dever::load("area/api.string", $member['area'], '-', true, '');
  500. $code = Dever::load("invite/api.code", $member['id']);
  501. $title = Dever::db('setting/title')->getDataByIds(array('id' => $member['title_id']));
  502. $title_name = array();
  503. if ($title) {
  504. foreach ($title as $k => $v) {
  505. $title_name[] = $v['name'];
  506. }
  507. }
  508. $title_name = implode('、', $title_name);
  509. if ($member['shop_id']) {
  510. $shop = Dever::db('shop/info')->one($member['shop_id']);
  511. } else {
  512. $shop['id'] = -1;
  513. $shop['name'] = '无';
  514. }
  515. $result = array();
  516. if ($level) {
  517. $role['name'] .= '(' . $level['name'] . ')';
  518. }
  519. if (!$member['cash']) {
  520. $member['cash'] = 0;
  521. }
  522. if (!$member['sell']) {
  523. $member['sell'] = 0;
  524. }
  525. if (!$member['group_sell']) {
  526. $member['group_sell'] = 0;
  527. }
  528. if (!$member['avatar']) {
  529. $default = Dever::db('passport/avatar')->one(1);
  530. $member['avatar'] = $default['avatar'];
  531. }
  532. if ($admin_auth) {
  533. $result = array
  534. (
  535. 'type' => 'user',
  536. 'pic' => $member['avatar'],
  537. 'content' => array
  538. (
  539. $member['name'],
  540. array('手机号', $member['mobile']),
  541. array('邀请码', $code),
  542. // array('代理商头衔', $title_name),
  543. array('代理角色', $role['name']),
  544. array('代理区域', $area),
  545. array('所属店铺', $shop['name']),
  546. array('资金余额', '<span style="color:blue">¥' . $member['cash'] . '元</span>'),
  547. // array('直推业绩', '<span style="color:blue">¥' . $member['sell'] . '元</span>'),
  548. // array('团队业绩', '<span style="color:blue">¥' . $member['group_sell'] . '元</span>'),
  549. ),
  550. );
  551. } else {
  552. $result = array
  553. (
  554. 'type' => 'user',
  555. 'pic' => $member['avatar'],
  556. 'content' => array
  557. (
  558. $member['name'],
  559. array('手机号', $member['mobile']),
  560. array('邀请码', $code),
  561. array('代理商头衔', $title_name),
  562. array('代理角色', $role['name']),
  563. array('代理区域', $area),
  564. array('所属店铺', $shop['name']),
  565. array('资金余额', '<span style="color:blue">¥' . $member['cash'] . '元</span>'),
  566. array('直推业绩', '<span style="color:blue">¥' . $member['sell'] . '元</span>'),
  567. array('团队业绩', '<span style="color:blue">¥' . $member['group_sell'] . '元</span>'),
  568. ),
  569. );
  570. }
  571. return $result;
  572. }
  573. public function setStatus_api()
  574. {
  575. $where['where_id'] = Dever::input('id');
  576. $where['status'] = Dever::input('value');
  577. Dever::db('agent/member')->update($where);
  578. return 'reload';
  579. }
  580. public function create($data)
  581. {
  582. $update['mobile'] = $data['mobile'];
  583. $info = Dever::db('agent/member')->find(array('mobile' => $data['mobile']));
  584. $update['name'] = $data['name'];
  585. $update['idcard'] = $data['idcard'];
  586. $update['idcard_front'] = $data['idcard_front'];
  587. $update['idcard_back'] = $data['idcard_back'];
  588. $update['company_name'] = $data['company_name'];
  589. $update['company_pic'] = $data['company_pic'];
  590. $update['company_number'] = $data['company_number'];
  591. $update['parent_mid'] = $data['parent_mid'];
  592. $update['source_id'] = $data['source_id'];
  593. $update['type'] = $data['type'];
  594. if (!$info) {
  595. $update['role'] = 1;
  596. $update['level_id'] = -1;
  597. $mid = Dever::db('agent/member')->insert($update);
  598. /*
  599. if ($mid && $data['parent_mid'] && $data['parent_mid'] > 0) {
  600. Dever::load('invite/api')->setRelation($mid, $data['parent_mid']);
  601. }
  602. */
  603. return $mid;
  604. } else {
  605. $update['where_id'] = $info['id'];
  606. Dever::db('agent/member')->update($update);
  607. return $info['id'];
  608. }
  609. }
  610. #认证时间
  611. public function set_rdate($id){
  612. $info=Dever::db('agent/member')->one(array('id'=>$id,'state'=>1));
  613. if($info['cdate']){
  614. $data['注册时间']=date('Y-m-d H:i',$info['cdate']);
  615. }else{
  616. $data['注册时间']='-';
  617. }
  618. if($info['status']==2){
  619. if($info['rdate']){
  620. $data['认证时间']=date('Y-m-d H:i',$info['rdate']);
  621. }else{
  622. $data['认证时间']='-';
  623. }
  624. }else{
  625. $data['认证时间']='-';
  626. }
  627. if($info['udate']){
  628. $data['终审时间']=date('Y-m-d H:i',$info['udate']);
  629. }else{
  630. $data['终审时间']='-';
  631. }
  632. // $html = Dever::table($data);
  633. return '注册时间:'.$data['注册时间'].'<br/>认证时间:'.$data['认证时间'].'<br/>终审时间:'.$data['终审时间'];
  634. }
  635. #更改收件人信息
  636. public function set_mobile($id){
  637. $info=Dever::db('agent/dh_order')->one(array('id'=>$id,'state'=>1));
  638. $data=array();
  639. if($info && $info['name']=='兑换商品'){
  640. $address=Dever::db('agent/member_address')->one(array('id'=>$info['address_id'],'state'=>1));
  641. if ($address) {
  642. $data['联系人']=$address['contact'];
  643. $data['联系电话']=$address['mobile'];
  644. $res=Dever::load('agent/lib/address')->getOne($address['mid'],$address['id']);
  645. $data['详细地址']=$res['address_info'].$address['house_number'];
  646. // $data['门牌号']=$address['house_number'];
  647. return $data['联系人'].'<br/>'.$data['联系电话'].'<br/>'.$data['详细地址'];
  648. } else {
  649. return '';
  650. }
  651. }else{
  652. return '';
  653. }
  654. // $html=Dever::table($data);
  655. // return $html;
  656. }
  657. public function daili($id){
  658. $info=Dever::db('agent/member')->one(array('id'=>$id,'state'=>1));
  659. $member['role'] = Dever::db('setting/role')->find($info['role']);
  660. $name ='<a href='.Dever::url('project/database/list&project=bill&table=sell&menu=bill&search_option_state=1&function=&method=search&search_api_mid='.$info['mobile'].'&search_fulltext_order_num=&search_option_start_cdate=&search_option_end_cdate=&excel=2&page_type=2', 'manage').'>'.$info['name'].'</a>';
  661. $mobile = $info['mobile'];
  662. $role = $member['role']['name'];
  663. if (isset($info['level_id']) && $info['level_id'] && $info['level_id'] > 0) {
  664. $info['level'] = Dever::db('setting/level')->find($info['level_id']);
  665. $role .= '('.$info['level']['name'].')';
  666. }
  667. $html = $name.'<br/>'.$mobile.'<br/>'.$role;
  668. return $html;
  669. }
  670. #上级信息
  671. public function sdaili($id){
  672. $res=Dever::db('agent/member')->one(array('id'=>$id,'state'=>1));
  673. if($res['parent_mid']>0){
  674. $info=Dever::db('agent/member')->one(array('id'=>$res['parent_mid'],'state'=>1));
  675. $member['role'] = Dever::db('setting/role')->find($info['role']);
  676. $data['姓名']='<a href='.Dever::url('project/database/list&project=bill&table=sell&menu=bill&search_option_state=1&function=&method=search&search_api_mid='.$info['mobile'].'&search_fulltext_order_num=&search_option_start_cdate=&search_option_end_cdate=&excel=2&page_type=2', 'manage').'>'.$info['name'].'</a>';
  677. $data['电话']=$info['mobile'];
  678. $data['角色']=$member['role']['name'];
  679. if (isset($info['level_id']) && $info['level_id'] && $info['level_id'] > 0) {
  680. $info['level'] = Dever::db('setting/level')->find($info['level_id']);
  681. $data['角色'] .= '('.$info['level']['name'].')';
  682. }
  683. $data['团队业绩']=$info['group_sell'];
  684. $html = $data['姓名'].'<br/>'.$data['电话'].'<br/>'.$data['角色'].'<br/>'.$data['团队业绩'];
  685. return $html;
  686. }elseif($res['source_id'] && $res['source_id'] >=1){
  687. $source=Dever::db('setting/source')->one(array('id'=>$res['source_id'],'state'=>1));
  688. $data['来源']=$source['name'];
  689. return $html =$data['来源'];
  690. }else{
  691. return '无';
  692. }
  693. }
  694. public function search_api()
  695. {
  696. $value = Dever::input('value');
  697. if ($value) {
  698. $parent_mid = Dever::load('invite/api')->getUid($value);
  699. $table = array();
  700. if ($parent_mid) {
  701. $member = Dever::db('agent/member')->find($parent_mid);
  702. if (!$member) {
  703. return '暂无账号';
  704. }
  705. $table = array();
  706. $table['head'] = array('姓名', '手机号');
  707. $table['body'] = array();
  708. $table['body'][] = array($member['name'], $member['mobile']);
  709. $result[] = array
  710. (
  711. 'type' => 'table',
  712. 'content' => $table,
  713. );
  714. $html = Dever::show('', $result, false, false);
  715. return $html;
  716. }
  717. return '暂无账号';
  718. } else {
  719. return '';
  720. }
  721. }
  722. #新增业绩(去掉直推最大一组市场,其他小组市场新增业绩之和)
  723. public function new_money($id){
  724. $start = Dever::input('search_option_start_dever_time');
  725. $end = Dever::input('search_option_end_dever_time');
  726. $where = array();
  727. $where['parent_mid'] = $id;
  728. // $info = Dever::db('bill/sell')->getNewChildParent($where);
  729. $member = Dever::db('agent/member')->getNewMember($where);
  730. $temp = array();
  731. $sell = 0;
  732. $total = 0;
  733. if($member){
  734. unset($member[0]);
  735. }
  736. if ($member) {
  737. foreach ($member as $k => $v) {
  738. if ($v['group_sell'] >=5000000) {
  739. unset($member[$k]);
  740. }
  741. }
  742. }
  743. // print_R($member);die;
  744. $where = array();
  745. if($start){
  746. $where['start'] = $start;
  747. }
  748. if($end){
  749. $where['end'] = $end;
  750. }
  751. $total = sprintf ('%01.2f',0);
  752. $where['state'] = 1;
  753. $where['type'] = 2;
  754. $where['stype'] = 1;
  755. if ($member) {
  756. $array = array_column($member, 'id');
  757. foreach($array as $k=>$v){
  758. $where['mid'] = $v;
  759. $info[] = Dever::db('bill/sell')->getNewChildParent($where);
  760. }
  761. if(isset($info) && $info){
  762. foreach($info as $k => $v){
  763. $total += $v['total'];
  764. }
  765. }
  766. $total = sprintf ('%01.2f',$total);
  767. }
  768. return $total;
  769. }
  770. #新增正常业绩
  771. public function new_zmoney($id){
  772. $start = Dever::input('search_option_start_dever_time');
  773. $end = Dever::input('search_option_end_dever_time');
  774. $where = array();
  775. if($start){
  776. $where['start'] = $start;
  777. }
  778. if($end){
  779. $where['end'] = $end;
  780. }
  781. $where['mid'] = $id;
  782. $where['state'] = 1;
  783. $where['type'] = 2;
  784. $where['stype'] = 1;
  785. $info = Dever::db('bill/sell')->getNewParent($where);
  786. $total = sprintf ('%01.2f',$info['total']);
  787. return $total;
  788. }
  789. #头衔统计数据导出
  790. public function out_member($data){
  791. $header = array('姓名', '手机号', '代理角色', '代理头衔', '直推业绩', '团队业绩', '新增业绩', '新增正常业绩');
  792. $body = array();
  793. foreach($data as $k => $v){
  794. $role = Dever::db('setting/role')->find($v['role']);
  795. $title = Dever::db('setting/title')->find($v['title_id']);
  796. $new_sell = $this->new_money($v['id']);
  797. $new_zsell = $this->new_zmoney($v['id']);
  798. $d = array
  799. (
  800. $v['name'],
  801. $v['mobile'],
  802. $role['name'],
  803. $title['name'],
  804. $v['sell'],
  805. $v['group_sell'],
  806. $new_sell,
  807. $new_zsell,
  808. );
  809. $body[] = $d;
  810. }
  811. $file = Dever::input('excel_name');
  812. return Dever::excelExport($body, $header, $file);
  813. }
  814. #归店记录明细导出(member_shop_log)
  815. public function out_member_shop_log ($data)
  816. {
  817. $header = array('姓名','手机号','代理角色','归店名称','归店时间');
  818. $body = array();
  819. if ($data) {
  820. foreach ($data as $k => $v) {
  821. $cdate = '';
  822. if ($v['cdate']) {
  823. $cdate = date('Y-m-d H:i',$v['cdate']);
  824. }
  825. $member_name = '';
  826. $member_mobile = '';
  827. $role_name = '';
  828. $member = Dever::db('agent/member')->find($v['mid']);
  829. if ($member) {
  830. $member_name = $member['name'];
  831. $member_mobile = $member['mobile'];
  832. $prize_type = '';
  833. if ($member['role']) {
  834. $role = Dever::db('setting/role')->find($member['role']);
  835. if ($role['id'] == 8) {
  836. if ($member['prize_type'] == 1) {
  837. $prize_type = '(名额外)';
  838. } elseif ($member['prize_type'] == 2) {
  839. $prize_type = '(名额内)';
  840. }
  841. }
  842. $role_name = $role['name'].$prize_type;
  843. }
  844. }
  845. $shop_name = '';
  846. if ($v['new_shop_id']) {
  847. $shop = Dever::db('shop/info')->find($v['new_shop_id']);
  848. if ($shop) {
  849. $shop_name = $shop['name'];
  850. }
  851. }
  852. $d = array
  853. (
  854. $member_name,
  855. $member_mobile,
  856. $role_name,
  857. $shop_name,
  858. $cdate,
  859. );
  860. $body[] = $d;
  861. }
  862. $file = Dever::input('excel_name');
  863. return Dever::excelExport($body, $header, $file);
  864. }
  865. }
  866. }