Manage.php 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757
  1. <?php
  2. namespace Agent\Lib;
  3. use Dever;
  4. class Manage
  5. {
  6. public function import($file)
  7. {
  8. $file = Dever::local($file);
  9. echo $file;die;
  10. }
  11. # 生成合同
  12. public function createAgreement_api()
  13. {
  14. $order_id = Dever::input('order_id');
  15. $order = Dever::db('agent/order')->find($order_id);
  16. if ($order) {
  17. $agreement = Dever::db('agent/member_agreement')->getData(array('order_id' => $order['id']));
  18. if (!$agreement) {
  19. if ($order['sign']) {
  20. $status = 2;
  21. } else {
  22. $status = 1;
  23. }
  24. Dever::load('agent/lib/agreement')->up($order, $status);
  25. }
  26. }
  27. return 'reload';
  28. }
  29. #代理商归店直推数据导出
  30. public function agentGuiout($data)
  31. {
  32. $file = Dever::input('excel_name');
  33. $header = array('姓名', '手机号', '所属店铺', '代理角色', '代理商区域', '代理费', '余额', '直推业绩', '团队业绩', '注册时间', '注册完成时间', '推荐人', '推荐人电话', '推荐人代理角色');
  34. $body = array();
  35. if ($data) {
  36. foreach ($data as $k => $v) {
  37. $shop_name = '';
  38. if ($v['shop_id'] && $v['shop_id'] > 0) {
  39. $shop = Dever::db('shop/info')->find($v['shop_id']);
  40. if ($shop) {
  41. $shop_name = $shop['name'];
  42. }
  43. }
  44. $prize_type = '';
  45. if (is_array($v)) {
  46. if ($v['role']) {
  47. $role = Dever::db('setting/role')->find($v['role']);
  48. if($v['role'] == 8){
  49. if($v['prize_type'] == 1){
  50. $prize_type = '-名额外';
  51. }elseif($v['prize_type'] == 2){
  52. $prize_type = '-名额内';
  53. }
  54. }
  55. } else {
  56. $role = array('name' => '普通代理',);
  57. }
  58. $order = Dever::db('agent/order')->find(array('mid' => $v['id']));
  59. $agent_cash = 0;
  60. if ($order) {
  61. $agent_cash = $order['agent_cash'];
  62. }
  63. $area = Dever::load("area/api.string", $v['area']);
  64. if ($v['rdate']) {
  65. $rdate = date('Y-m-d H:i',$v['rdate']);
  66. } else {
  67. $rdate = '-';
  68. }
  69. $parent_name = '';
  70. $parent_mobile = '';
  71. $parent_rolename = '';
  72. if ($v['parent_mid'] && $v['parent_mid'] > 0) {
  73. $parent = Dever::db('agent/member')->find(array('id'=>$v['parent_mid']));
  74. if ($parent) {
  75. if($parent['role']){
  76. $parent_role = Dever::db('setting/role')->find(array('id'=>$parent['role']));
  77. if($parent_role){
  78. $parent_rolename = $parent_role['name'];
  79. }
  80. }
  81. if($parent['name']){
  82. $parent_name = $parent['name'];
  83. }
  84. if($parent['mobile']){
  85. $parent_mobile = $parent['mobile'];
  86. }
  87. }
  88. }
  89. $d = array
  90. (
  91. $v['name'],
  92. $v['mobile'],
  93. $shop_name,
  94. $role['name'].$prize_type,
  95. $area,
  96. $agent_cash,
  97. $v['cash'],
  98. $v['sell'],
  99. $v['group_sell'],
  100. date('Y-m-d H:i',$v['cdate']),
  101. $rdate,
  102. $parent_name,
  103. $parent_mobile,
  104. $parent_rolename,
  105. );
  106. $body[] = $d;
  107. }
  108. }
  109. }
  110. return Dever::excelExport($body, $header, $file);
  111. }
  112. public function agentOut($data)
  113. {
  114. $file = Dever::input('excel_name');
  115. $header = array('姓名', '手机号', '身份证号', '代理角色', '代理商区域', '代理费', '余额', '直推业绩', '团队业绩', '注册时间', '注册完成时间', '推荐人', '推荐人电话', '推荐人代理角色');
  116. $body = array();
  117. if ($data) {
  118. foreach ($data as $k => $v) {
  119. $prize_type = '';
  120. if (is_array($v)) {
  121. if ($v['role']) {
  122. $role = Dever::db('setting/role')->find($v['role']);
  123. if($v['role'] == 8){
  124. if($v['prize_type'] == 1){
  125. $prize_type = '-名额外';
  126. }elseif($v['prize_type'] == 2){
  127. $prize_type = '-名额内';
  128. }
  129. }
  130. } else {
  131. $role = array('name' => '普通代理',);
  132. }
  133. $order = Dever::db('agent/order')->find(array('mid' => $v['id']));
  134. $agent_cash = 0;
  135. if ($order) {
  136. $agent_cash = $order['agent_cash'];
  137. }
  138. $area = Dever::load("area/api.string", $v['area']);
  139. if ($v['rdate']) {
  140. $rdate = date('Y-m-d H:i',$v['rdate']);
  141. } else {
  142. $rdate = '-';
  143. }
  144. $parent_name = '';
  145. $parent_mobile = '';
  146. $parent_rolename = '';
  147. if ($v['parent_mid'] && $v['parent_mid'] > 0) {
  148. $parent = Dever::db('agent/member')->find(array('id'=>$v['parent_mid']));
  149. if ($parent) {
  150. if($parent['role']){
  151. $parent_role = Dever::db('setting/role')->find(array('id'=>$parent['role']));
  152. if($parent_role){
  153. $parent_rolename = $parent_role['name'];
  154. }
  155. }
  156. if($parent['name']){
  157. $parent_name = $parent['name'];
  158. }
  159. if($parent['mobile']){
  160. $parent_mobile = $parent['mobile'];
  161. }
  162. }
  163. }
  164. $d = array
  165. (
  166. $v['name'],
  167. $v['mobile'],
  168. $v['idcard'],
  169. $role['name'].$prize_type,
  170. $area,
  171. $agent_cash,
  172. $v['cash'],
  173. $v['sell'],
  174. $v['group_sell'],
  175. date('Y-m-d H:i',$v['cdate']),
  176. $rdate,
  177. $parent_name,
  178. $parent_mobile,
  179. $parent_rolename,
  180. );
  181. $body[] = $d;
  182. }
  183. }
  184. }
  185. return Dever::excelExport($body, $header, $file);
  186. }
  187. public function agentCashOut($data)
  188. {
  189. $db = Dever::db('agent/test:old');
  190. $file = Dever::input('excel_name');
  191. $header = array('姓名', '手机号', '代理角色', '交款金额', '直推佣金', '团队佣金', '注册时间');
  192. $body = array();
  193. if ($data) {
  194. foreach ($data as $k => $v) {
  195. if ($v['rdate'] > 0) {
  196. if ($v['role']) {
  197. $role = Dever::db('setting/role')->find($v['role']);
  198. } else {
  199. $role = array('name' => '普通代理',);
  200. }
  201. $order = Dever::db('agent/order')->find(array('mid' => $v['id']));
  202. $price = 0;
  203. if ($order) {
  204. $price = $order['price'];
  205. }
  206. $cash_zt = 0;
  207. $cash_group = 0;
  208. $cash = Dever::db('bill/cash')->getCash(array('type' => 1, 'mid' => $v['id']));
  209. if ($cash) {
  210. $cash_zt = $cash['total'];
  211. }
  212. $cash = Dever::db('bill/cash')->getCash(array('type' => 2, 'mid' => $v['id']));
  213. if ($cash) {
  214. $cash_group = $cash['total'];
  215. }
  216. if (!$cash_group) {
  217. $cash_group = 0;
  218. }
  219. if ($v['id'] < 50000) {
  220. $info = $db->fetch('select * from ims_ewei_shop_member where id = ' . $v['id']);
  221. if ($info) {
  222. $member = $db->fetch('select * from ims_mc_members where uid = ' . $info['uid']);
  223. $cash_zt += ($member && $member['credit2']) ? $member['credit2'] : $info['credit2'];
  224. }
  225. }
  226. $cdate = date('Y-m-d H:i', $v['rdate']);
  227. $d = array
  228. (
  229. $v['name'],
  230. $v['mobile'],
  231. $role['name'],
  232. $price,
  233. $cash_zt,
  234. $cash_group,
  235. $cdate,
  236. );
  237. $body[] = $d;
  238. }
  239. }
  240. }
  241. return Dever::excelExport($body, $header, $file);
  242. }
  243. public function relation_api()
  244. {
  245. $admin = Dever::load('manage/auth.data');
  246. if ($admin['role'] != 1) {
  247. Dever::alert('无法访问');
  248. }
  249. $data = array();
  250. $data['mobile'] = Dever::input('mobile');
  251. $member = Dever::db('agent/member')->find(array('mobile' => $data['mobile']));
  252. $data['mid'] = $member['id'];
  253. // Dever::input('mid');
  254. $data['link'] = Dever::decode(Dever::input('refer'));
  255. return Dever::render('index', $data);
  256. }
  257. # 后台设置区域
  258. public function updateArea($id, $name, $data)
  259. {
  260. Dever::config('base')->hook = true;
  261. $id = $id['where_id'];
  262. $is_area = Dever::param('is_area', $data);
  263. $area = Dever::param('area', $data);#修改后
  264. $role = Dever::param('role', $data);
  265. $level_id = Dever::param('level_id', $data);
  266. $member = Dever::db('agent/member')->find($id);
  267. if (!$member) {
  268. return;
  269. }
  270. if (!$is_area) {
  271. $is_area = 1;
  272. }
  273. if ($is_area == 1) {
  274. if ($area && is_array($area) && $role) {
  275. $role = Dever::db('setting/role')->find($role);
  276. $area_string = array();
  277. if ($role && $role['type'] == 2) {
  278. $area_string = Dever::load('agent/lib/order')->checkArea($area, $role, $member['id']);
  279. } else {
  280. $area_string = implode(',', $area);
  281. }
  282. $area_string = str_replace(',-1', '', $area_string);
  283. $data['set_area'] = $area_string;
  284. if ($area_string == $member['area']) {
  285. $area_string = '';
  286. }
  287. $this->upLog($member, $role, $area_string, -1, 3);
  288. }
  289. } else {
  290. # 清理区域
  291. $role = Dever::db('setting/role')->find($member['role']);
  292. if ($role && $role['type'] == 2) {
  293. $area = $member['area'];
  294. Dever::load('area/api')->upStatus($area, 1);
  295. $area_data['mid'] = $member['id'];
  296. $area_data['area'] = $area;
  297. $area_info = Dever::db('agent/member_area')->find($area_data);
  298. if ($area_info) {
  299. Dever::db('agent/member_area')->update(array('where_id' => $area_info['id'], 'state' => 2));
  300. Dever::db('agent/member')->update(array('where_id' => $member['id'], 'area' => ''));
  301. //Dever::load('agent/lib/order')->editArea($member, '');
  302. $this->area_log($member['id'], -1, $member['area'], '');
  303. }
  304. $data['set_area'] = 'null';
  305. }
  306. }
  307. if ($level_id && $level_id != $member['level_id']) {
  308. $group_num = Dever::load('invite/api')->getChildNum($member['id'], 1);
  309. Dever::load('agent/lib/level_log')->up($member['id'], -1, $member['level_id'], $level_id, 0, 0, $group_num);
  310. }
  311. $name = Dever::param('name', $data);
  312. if ($name) {
  313. $order = Dever::db('agent/order')->select(array('mid' => $member['id']));
  314. if ($order) {
  315. foreach ($order as $k => $v) {
  316. if ($v['status'] <= 2) {
  317. Dever::db('agent/order')->update(array('where_id' => $v['id'], 'name' => $name));
  318. }
  319. }
  320. }
  321. }
  322. $mobile = Dever::param('mobile', $data);
  323. if ($mobile) {
  324. # 验证手机号是否可以修改
  325. $mobile_member = Dever::db('agent/member')->find(array('mobile' => $mobile));
  326. if ($mobile_member && $mobile_member['id'] != $member['id']) {
  327. Dever::alert('无法修改手机号,当前手机号已被代理商'.$mobile_member['name'].'使用');
  328. }
  329. # 是否同步修改期权表
  330. $option_member = Dever::db('option/member')->find(array('mobile' => $member['mobile'], 'main' => 2));
  331. if ($option_member) {
  332. $mobile_member = Dever::db('option/member')->find(array('mobile' => $mobile));
  333. if ($mobile_member && $mobile_member['id'] != $option_member['id']) {
  334. Dever::alert('无法修改手机号,当前手机号已被代理商期权账户'.$mobile_member['name'].'使用');
  335. }
  336. Dever::db('option/member')->update(array('where_id' => $option_member['id'], 'mobile' => $mobile));
  337. }
  338. # 同步修改其他表的手机号
  339. Dever::db('agent/member_agreement')->updates(array('option_mid' => $member['id'], 'set_mobile' => $mobile));
  340. Dever::db('agent/dh_order')->updates(array('option_mid' => $member['id'], 'set_mobile' => $mobile));
  341. Dever::db('agent/order')->updates(array('option_mid' => $member['id'], 'set_mobile' => $mobile));
  342. Dever::db('agent/user_bind')->updates(array('option_mid' => $member['id'], 'set_mobile' => $mobile));
  343. Dever::db('agent/soft_cash')->updates(array('option_mid' => $member['id'], 'set_mobile' => $mobile));
  344. //Dever::db('active/user')->updates(array('option_mobile' => $member['mobile'], 'set_mobile' => $mobile));
  345. }
  346. $shop_id = Dever::param('shop_id', $data);
  347. if ($shop_id && $member['shop_id'] != $shop_id) {
  348. $insert['mid'] = $member['id'];
  349. $insert['new_shop_id'] = $shop_id;
  350. $insert['clear'] = true;
  351. $info = Dever::db('agent/member_shop_log')->find($insert);
  352. if (!$info) {
  353. $insert['old_shop_id'] = $member['shop_id'];
  354. Dever::db('agent/member_shop_log')->insert($insert);
  355. }
  356. }
  357. return $data;
  358. }
  359. # 更改日志
  360. private function upLog($member, $role, $area, $order_id = -1, $type = 3, $price = 0)
  361. {
  362. if (is_numeric($role)) {
  363. $role = Dever::db('setting/role')->find($role);
  364. }
  365. if (!$role) {
  366. return;
  367. }
  368. $this->upRole($member, $role, $area, $order_id);
  369. if ($area) {
  370. $this->upArea($member, $role, $area, $order_id, $type, $price);
  371. }
  372. }
  373. private function upRole($member, $role, $area, $order_id = -1)
  374. {
  375. if ($role['id'] == $member['role']) {
  376. return;
  377. }
  378. $data['mid'] = $member['id'];
  379. $data['order_id'] = $order_id;
  380. $data['old_role'] = $member['role'];
  381. $data['new_role'] = $role['id'];
  382. if ($area) {
  383. $data['area'] = $area;
  384. } else {
  385. $data['area'] = $member['area'];
  386. }
  387. if ($order_id && $order_id > 0) {
  388. $data['type'] = 1;
  389. $order = Dever::db('agent/order')->find($order_id);
  390. $data['price'] = $order['price'];
  391. } else {
  392. $data['type'] = 2;
  393. $admin = Dever::load('manage/auth.info');
  394. $data['audit_admin'] = $admin['id'];
  395. }
  396. Dever::db('agent/member_account_log')->insert($data);
  397. }
  398. public function upArea($member, $role, $area, $order_id = -1, $type = 3, $price = 0)
  399. {
  400. if (!$role) {
  401. return;
  402. }
  403. if ($area == $member['area']) {
  404. //return;
  405. }
  406. $area_data = array('mid' => $member['id']);
  407. $area_info = Dever::db('agent/member_area')->select($area_data);
  408. if ($area_info) {
  409. foreach ($area_info as $k => $v) {
  410. Dever::load('area/api')->upStatus($v['area'], 1);
  411. Dever::db('agent/member_area')->update(array('where_id' => $v['id'], 'state' => 2));
  412. }
  413. }
  414. if ($role && $role['type'] == 2) {
  415. Dever::load('area/api')->upStatus($area, 2);
  416. $area_data['order_id'] = $order_id;
  417. $area_data['role'] = $role['id'];
  418. $area_data['area'] = $area;
  419. $area_data['type'] = $type;
  420. $area_data['price'] = $price;
  421. $area_data['status'] = 1;
  422. Dever::db('agent/member_area')->insert($area_data);
  423. //Dever::load('agent/lib/order')->editArea($v, $area);
  424. }
  425. $this->area_log($member['id'], $order_id, $member['area'], $area);
  426. }
  427. # 获取
  428. # 设置上级
  429. public function setParent_commit($id, $name, $data)
  430. {
  431. //Dever::alert('暂未开放');
  432. Dever::config('base')->hook = true;
  433. $mid = Dever::param('mid', $data);
  434. $parent_mobile = trim(Dever::param('parent_mobile', $data));
  435. if ($mid && $parent_mobile) {
  436. $member = Dever::db('agent/member')->find($mid);
  437. $parent = Dever::db('agent/member')->find(array('mobile' => $parent_mobile));
  438. if ($parent && $parent['status'] == 2) {
  439. if ($member['parent_mid'] == $parent['id']) {
  440. Dever::alert('上级代理商设置失败');
  441. return;
  442. }
  443. if ($member['parent_mid'] == $mid) {
  444. Dever::alert('上级代理商不能设置为自己');
  445. return;
  446. }
  447. # 重置关系
  448. Dever::load('invite/api')->resetRelation($mid, $parent['id']);
  449. /*
  450. # 删除之前关系
  451. Dever::load('invite/api')->dropRelation($mid, $parent['id']);
  452. # 获取所有下级
  453. $child = Dever::load('invite/api')->getChild($mid);
  454. if ($child) {
  455. foreach ($child as $k => $v) {
  456. Dever::load('invite/api')->dropRelation($v['to_uid'], $parent['id']);
  457. }
  458. }
  459. # 重新设置关系
  460. Dever::load('invite/api')->setRelation($mid, $parent['id']);
  461. */
  462. Dever::db('agent/member')->update(array('where_id' => $mid, 'parent_mid' => $parent['id']));
  463. } else {
  464. Dever::alert('上级代理商还未注册或者已封禁');
  465. }
  466. }
  467. }
  468. public function orderUpdateParent($id, $name, $data)
  469. {
  470. Dever::config('base')->hook = true;
  471. $id = $id['where_id'];
  472. $order = Dever::db('agent/order')->find($id);
  473. if (!$order) {
  474. return;
  475. }
  476. $area = Dever::param('area', $data);#修改后
  477. $role = Dever::param('role', $data);
  478. $invite_type = Dever::param('invite_type', $data);
  479. $parent_code = Dever::param('parent_code', $data);
  480. if ($invite_type == 1 && $parent_code) {
  481. $parent_mid = Dever::load('invite/api')->getUid($parent_code);
  482. if ($parent_mid) {
  483. $parent_member = Dever::db('agent/member')->find($parent_mid);
  484. if (!$parent_member) {
  485. Dever::alert('错误的邀请码');
  486. }
  487. if ($order['mid'] == $parent_member['id']) {
  488. Dever::alert('邀请人不能是自己');
  489. }
  490. $data['set_parent_mid'] = $parent_mid;
  491. //Dever::db('agent/member')->update(array('where_id' => $order['mid'], 'parent_mid' => $parent_mid));
  492. } else {
  493. Dever::alert('错误的邀请码');
  494. }
  495. }
  496. if ($area && is_array($area) && $role) {
  497. $role = Dever::db('setting/role')->find($role);
  498. $area_string = array();
  499. if ($role && $role['type'] == 2) {
  500. $area_string = Dever::load('agent/lib/order')->checkArea($area, $role, $order['mid']);
  501. } else {
  502. $area_string = implode(',', $area);
  503. $area_string = str_replace(',-1', '', $area_string);
  504. }
  505. if ($role['type'] == 1) {
  506. $data['set_f_price'] = $data['set_price'] = $role['price'];
  507. } elseif ($role['type'] == 2) {
  508. $data['set_f_price'] = $data['set_price'] = Dever::load('area/api')->getPrice($role['area'], $area_string);
  509. } else {
  510. $data['set_f_price'] = $data['set_price'] = 0;
  511. }
  512. $data['set_area'] = $area_string;
  513. }
  514. return $data;
  515. }
  516. public function orderStartUpdate($id, $name, $data)
  517. {
  518. $order_id = Dever::param('order_id', $data);
  519. if ($order_id) {
  520. $order = Dever::db('agent/order')->find($order_id);
  521. if ($order) {
  522. $status = Dever::param('status', $data);
  523. if ($status) {
  524. $role = Dever::db('setting/role')->find($order['role']);
  525. if ($role && $role['type'] == 2) {
  526. Dever::load('agent/lib/order')->checkArea($order['area'], $role, $order['mid']);
  527. }
  528. }
  529. if ($order['source_id'] < 0) {
  530. if ($order['parent_mid'] > 0) {
  531. $member = Dever::db('agent/member')->find($order['parent_mid']);
  532. if ($member['status'] == 2) {
  533. return $data;
  534. }
  535. }
  536. Dever::alert('直属上级未认证,无法进行初审');
  537. }
  538. }
  539. }
  540. }
  541. public function orderUpdate($id, $name, $data)
  542. {
  543. Dever::config('base')->hook = true;
  544. $audit = Dever::param('audit', $data);
  545. $status = Dever::param('status', $data);
  546. $desc = Dever::param('desc', $data);
  547. $order_id = Dever::param('order_id', $data);
  548. $order = Dever::db('agent/order')->find($order_id);
  549. if ($order_id && $order && $status) {
  550. $admin = Dever::load('manage/auth.info');
  551. if ($admin) {
  552. Dever::db('agent/order_process')->update(array('where_id' => $id, 'admin' => $admin['id']));
  553. }
  554. if ($status < 3) {
  555. if ($audit == 1) {
  556. $update = array('where_id' => $order_id, 'status' => $status+1);
  557. if ($status == 1) {
  558. $soft_price = Dever::param('soft_price', $data);
  559. $price = Dever::param('price', $data);
  560. $prize_type = Dever::param('prize_type', $data);
  561. $option_price = Dever::param('option_price', $data);
  562. if ($prize_type == 2) {
  563. # 扣减已有名额,判断一下 暂时废弃
  564. $prize = Dever::db('setting/prize')->find(array('type' => 1, 'price' => $order['price']));
  565. if ($prize) {
  566. $member_goods = Dever::db('agent/member_goods')->getOne(array('mid' => $order['mid'], 'type' => 3, 'type_id' => $prize['id']));
  567. if ($member_goods && $member_goods['num'] > 0) {
  568. # 有名额
  569. $price = 0;
  570. # 开始扣减
  571. $member = Dever::db('agent/member')->find($order['mid']);
  572. Dever::load('agent/lib/dhorder')->action($member, $prize['name'], $prize['num'], $prize['price'], array(), -1, 2, 3, $prize['id'], $desc);
  573. }
  574. }
  575. }
  576. if ($price <= 0) {
  577. $update['get_type'] = 2;
  578. } else {
  579. $update['get_type'] = 1;
  580. }
  581. $update['price'] = $price;
  582. $update['agent_cash'] = $price;
  583. $update['soft_cash'] = 0;
  584. $update['option_price']=$option_price;
  585. $cstatus = Dever::param('cstatus', $data);
  586. if ($cstatus && $cstatus == 2 && $price > 0) {
  587. # 拆分代理费
  588. if ($soft_price > 0) {
  589. $update['agent_cash'] = $price - $soft_price;
  590. $update['soft_cash'] = $soft_price;
  591. } else {
  592. $role = Dever::db('setting/role')->one($order['role']);
  593. if ($role && $role['soft']) {
  594. if (strstr($role['soft'], '%')) {
  595. $role['soft'] = str_replace('%', '', $role['soft']);
  596. $role['soft'] = $price * ($role['soft']/100);
  597. }
  598. $update['agent_cash'] = $price - $role['soft'];
  599. $update['soft_cash'] = $role['soft'];
  600. }
  601. }
  602. }
  603. # 增加业绩
  604. //Dever::load('bill/lib/sell')->up($order['mid'], 2, $order['price'], $order['role'], $order['id'], $order['name'] . '成为代理商');
  605. } elseif ($status == 2) {
  606. if ($order['mid'] && $order['mid'] > 0 && $order['parent_mid'] && $order['parent_mid'] > 0) {
  607. Dever::load('invite/api')->setRelation($order['mid'], $order['parent_mid']);
  608. Dever::db('agent/member')->update(array('where_id' => $order['mid'], 'parent_mid' => $order['parent_mid']));
  609. }
  610. $update['pay_status'] = 2;
  611. Dever::load('agent/lib/member')->create($order);
  612. }
  613. Dever::db('agent/order')->update($update);
  614. } else {
  615. Dever::db('agent/order')->update(array('where_id' => $order_id, 'status' => 5, 'history_status' => $order['status'], 'audit_desc' => $desc));
  616. if (Dever::project('sms')) {
  617. Dever::load('sms/api')->send('daili_reg_no', $order['mobile'], array('name' => $order['name'], 'content' => $desc));
  618. }
  619. }
  620. } elseif ($status == 3) {
  621. $info = Dever::db('agent/order_process')->find(array('id' => $id, 'clear' => true));
  622. if ($info && $info['status'] == 3) {
  623. $info['type'] = explode(',', $info['type']);
  624. }
  625. if (in_array(2, $info['type'])) {
  626. $goods_status = 3;
  627. } else {
  628. $goods_status = 2;
  629. }
  630. $curtime = time();
  631. Dever::db('agent/order')->update(array('where_id' => $order_id, 'fdate' => $curtime, 'status' => 4, 'goods_status' => $goods_status));
  632. # 通知短信
  633. if (Dever::project('sms')) {
  634. $order = Dever::db('agent/order')->find($order_id);
  635. Dever::load('sms/api')->send('daili_reg_yes', $order['mobile'], array('name' => $order['name']));
  636. }
  637. $order = Dever::db('agent/order')->find($order_id);
  638. if ($order && $order['mid']) {
  639. $member = Dever::db('agent/member')->find($order['mid']);
  640. $update['where_id'] = $order['mid'];
  641. if ($member && $member['status'] == 1) {
  642. $update['status'] = 2;
  643. $update['rdate'] = $curtime;
  644. }
  645. $update['area'] = $order['area'];
  646. $update['role'] = $order['role'];
  647. $update['udate'] = $curtime;
  648. Dever::db('agent/member')->update($update);
  649. if ($order['price'] > 0) {
  650. $type = 1;
  651. } else {
  652. $type = 2;
  653. }
  654. $this->upLog($member, $order['role'], $order['area'], $order['id'], $type, $order['price']);
  655. }
  656. }
  657. }
  658. }
  659. #区域日志
  660. public function area_log($mid,$order_id,$old_area, $area) {
  661. $data['mid']=$mid;
  662. $data['order_id']=$order_id;
  663. $data['old_area']=$old_area;
  664. $data['area']=$area;
  665. if ($order_id && $order_id > 0) {
  666. $data['type'] = 1;
  667. } else {
  668. $admin = Dever::load('manage/auth.info');
  669. $data['audit_admin'] = $admin['id'];
  670. $data['type'] = 2;
  671. }
  672. $id = Dever::db('agent/member_area_log')->insert($data);
  673. return $id;
  674. }
  675. # 发放权益
  676. public function set_commit_api()
  677. {
  678. Dever::config('base')->hook = true;
  679. $type = Dever::input('type', 2);
  680. $order_id = Dever::input('order_id');
  681. # 检测是否发放过了
  682. $order = Dever::db('agent/order')->find($order_id);
  683. if ($order['status'] != 3) {
  684. //Dever::alert('无发放权限');
  685. }
  686. $order_process = Dever::db('agent/order_process')->find(array('order_id' => $order_id, 'status' => 3));
  687. $yes = -1;
  688. if (!$order_process) {
  689. # 可以发放
  690. $yes = 1;
  691. } elseif ($order_process) {
  692. $order_process['type'] = explode(',', $order_process['type']);
  693. if (!in_array($type, $order_process['type'])) {
  694. # 可以发放
  695. $yes = 2;
  696. }
  697. }
  698. if ($yes > 0) {
  699. if ($yes == 1) {
  700. $data['order_id'] = $order_id;
  701. $data['status'] = 3;
  702. $data['type'] = '1,' . $type;
  703. $state = Dever::db('agent/order_process')->insert($data);
  704. } else {
  705. $data['where_id'] = $order_process['id'];
  706. $order_process['type'][] = $type;
  707. $data['type'] = implode(',', $order_process['type']);
  708. $state = Dever::db('agent/order_process')->update($data);
  709. }
  710. if ($state) {
  711. if ($type == 2) {
  712. $this->setGoods($order);
  713. } elseif ($type == 3) {
  714. $this->setCash($order);
  715. } elseif ($type == 5) {
  716. $this->setAgreement($order);
  717. }
  718. }
  719. return 'reload';
  720. } else {
  721. Dever::alert('无发放权限');
  722. }
  723. }
  724. # 设置多个权益
  725. private function setGoods($order)
  726. {
  727. $t = 1;
  728. $goods = Dever::db('agent/order_goods')->getData(array('order_id' => $order['id']));
  729. if (!$goods) {
  730. $goods = Dever::db('setting/role_goods')->getData(array('role_id' => $order['role'], 'give' => $order['order_type']));
  731. $t = intval($order['agent_cash']/10000);
  732. if ($t <= 0) {
  733. $t = 1;
  734. }
  735. }
  736. if ($goods) {
  737. $where = array();
  738. $goods_cash = 0;
  739. foreach ($goods as $k => $v) {
  740. $order_goods = array();
  741. $order_goods['order_id'] = $order['id'];
  742. $order_goods['type'] = $v['type'];
  743. $order_goods['type_id'] = $v['type_id'];
  744. $order_goods['sku_id'] = $v['sku_id'];
  745. $order_goods['num'] = $v['num'];
  746. Dever::db('agent/order_goods')->insert($order_goods);
  747. $price = $this->addGoods($order, $v, $t);
  748. if ($price && $v['type'] < 3) {
  749. # 计算商品价值
  750. $goods_cash += $price;
  751. }
  752. }
  753. $update = array();
  754. if ($goods_cash) {
  755. $update['goods_cash'] = $goods_cash;
  756. }
  757. $update['goods_status'] = 3;
  758. $update['where_id'] = $order['id'];
  759. Dever::db('agent/order')->update($update);
  760. }
  761. }
  762. # 新增权益
  763. private function addGoods($order, $v, $t)
  764. {
  765. $cash = $price = 0;
  766. if ($v['type'] == 1) {
  767. $v['num'] = $v['num'] * $t;
  768. $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v['type_id'], $v['sku_id']);
  769. $price = $goods_info['price'];
  770. $cash = $goods_info['price'] * $v['num'];
  771. if (isset($goods_info['sku'])) {
  772. $sku = '-' . $goods_info['sku']['string'];
  773. } else {
  774. $sku = '';
  775. }
  776. $name = $goods_info['name'] . $sku;
  777. } elseif ($v['type'] == 2) {
  778. $v['sku_id'] = -1;
  779. # 生成一个电子券
  780. $card = Dever::db('card/info')->find($v['type_id']);
  781. if (!$card) {
  782. return false;
  783. }
  784. $name = $card['name'];
  785. if ($card['create_type'] == 2) {
  786. $cash = $card['value']*$v['num'] * $t;
  787. $price = $cash;
  788. $v['num'] = 1;
  789. $v['sku_id'] = Dever::load('card/lib/code')->create($card, 2, $order['mid'], $order['id'], $cash);
  790. if (!$v['sku_id']) {
  791. return false;
  792. }
  793. } elseif ($card['create_type'] == 3) {
  794. $cash = round($order['agent_cash']*($v['num']/100), 2);
  795. $price = $cash;
  796. $v['num'] = 1;
  797. $v['sku_id'] = Dever::load('card/lib/code')->create($card, 2, $order['mid'], $order['id'], $cash);
  798. if (!$v['sku_id']) {
  799. return false;
  800. }
  801. } else {
  802. $cash = $card['value'];
  803. $price = $cash;
  804. $total = $t*$v['num'];
  805. $t = 1;
  806. for($i=0; $i<$total;$i++) {
  807. $v['sku_id'] = Dever::load('card/lib/code')->create($card, 2, $order['mid'], $order['id'], $cash);
  808. if ($v['sku_id']) {
  809. $where['mid'] = $order['mid'];
  810. $where['type'] = $v['type'];
  811. $where['type_id'] = $v['type_id'];
  812. $where['sku_id'] = $v['sku_id'];
  813. $info = Dever::db('agent/member_goods')->find($where);
  814. if (!$info) {
  815. $up = $where;
  816. $up['total_num'] = $t;
  817. $up['cash'] = $cash;
  818. $up['price'] = $price;
  819. $up['name'] = $name;
  820. $state = Dever::db('agent/member_goods')->insert($up);
  821. if ($state) {
  822. Dever::load('agent/lib/member_set')->log($order['mid'], $order['order_num'], $v['type'], $v['type_id'], $v['sku_id'], $t, 0, $t, $name);
  823. }
  824. }
  825. }
  826. }
  827. return $cash * $total;
  828. }
  829. } elseif ($v['type'] == 3) {
  830. $prize = Dever::db('setting/prize')->find($v['type_id']);
  831. $v['num'] = $v['num'] * $t;
  832. $role = Dever::db('setting/role')->find($order['role']);
  833. if ($role && $role['max_me_num'] && $role['max_me_num'] < $v['num']) {
  834. $v['num'] = $role['max_me_num'];
  835. }
  836. $price = $prize['price'];
  837. $cash = $prize['price']*$v['num'];
  838. $name = $prize['name'];
  839. }
  840. $where['mid'] = $order['mid'];
  841. $where['type'] = $v['type'];
  842. $where['type_id'] = $v['type_id'];
  843. $where['sku_id'] = $v['sku_id'];
  844. $info = Dever::db('agent/member_goods')->find($where);
  845. if ($info) {
  846. $up['where_id'] = $info['id'];
  847. $up['total_num'] = $info['total_num'] + $v['num'];
  848. $up['cash'] = $cash;
  849. $up['price'] = $price;
  850. $up['name'] = $name;
  851. $state = Dever::db('agent/member_goods')->update($up);
  852. if ($state) {
  853. Dever::load('agent/lib/member_set')->log($order['mid'], $order['order_num'], $v['type'], $v['type_id'], $v['sku_id'], $v['num'], $info['total_num'], $up['total_num'], $name);
  854. }
  855. } else {
  856. $up = $where;
  857. $up['total_num'] = $v['num'];
  858. $up['cash'] = $cash;
  859. $up['price'] = $price;
  860. $up['name'] = $name;
  861. $state = Dever::db('agent/member_goods')->insert($up);
  862. if ($state) {
  863. Dever::load('agent/lib/member_set')->log($order['mid'], $order['order_num'], $v['type'], $v['type_id'], $v['sku_id'], $v['num'], 0, $up['total_num'], $name);
  864. }
  865. }
  866. return $cash;
  867. }
  868. private function setCash($order)
  869. {
  870. $param = Dever::input('param');
  871. if ($param) {
  872. $param = explode(',', $param);
  873. foreach ($param as $k => $v) {
  874. $t = Dever::array_decode($v);
  875. $parent_order = $order;
  876. $parent_order['mid'] = $t['parent_mid'];
  877. $where['type'] = $t['type'];
  878. $where['order_id'] = $order['id'];
  879. $where['mid'] = $order['mid'];
  880. $where['parent_mid'] = $t['parent_mid'];
  881. $info = Dever::db('agent/order_cash')->find($where);
  882. if (!$info) {
  883. $insert = $where;
  884. $insert['cash'] = $t['cash'];
  885. $insert['per'] = $t['per'];
  886. if (isset($t['prize_id'])) {
  887. $insert['prize_id'] = $t['prize_id'];
  888. }
  889. if (isset($t['goods'])) {
  890. $insert['goods'] = Dever::array_encode($t['goods']);
  891. }
  892. Dever::db('agent/order_cash')->insert($insert);
  893. } else {
  894. $update['where_id'] = $info['id'];
  895. $update['cash'] = $t['cash'];
  896. $update['per'] = $t['per'];
  897. if (isset($t['prize_id'])) {
  898. $update['prize_id'] = $t['prize_id'];
  899. }
  900. if (isset($t['goods'])) {
  901. $update['goods'] = Dever::array_encode($t['goods']);
  902. }
  903. Dever::db('agent/order_cash')->update($update);
  904. }
  905. if (isset($t['prize_id']) && isset($t['child_num'])) {
  906. $prize_info = Dever::db('setting/prize')->find($t['prize_id']);
  907. if ($prize_info) {
  908. $prize_insert['order_id'] = $order['order_id'];
  909. $prize_insert['mid'] = $t['parent_mid'];
  910. $prize_insert['child_num'] = $t['child_num'];
  911. $prize_insert['prize_id'] = $prize_info['id'];
  912. Dever::db('agent/member_prize')->insert($prize_insert);
  913. $prize['type'] = 3;
  914. $prize['type_id'] = $prize_info['id'];
  915. $prize['sku_id'] = -1;
  916. $prize['num'] = $prize_info['num'];
  917. $this->addGoods($parent_order, $prize, 1);
  918. }
  919. }
  920. if (isset($t['parent_goods_id'])) {
  921. $parent_goods = Dever::db('agent/member_goods')->getOne(array('id' => $t['parent_goods_id']));
  922. if ($parent_goods && $parent_goods['num'] > 0) {
  923. $parent_prize = Dever::db('setting/prize')->find($parent_goods['type_id']);
  924. if ($parent_prize) {
  925. # 判断是否名额内
  926. if (isset($t['prize_type']) && $t['prize_type'] == 2) {
  927. Dever::db('agent/member')->update(array('where_id' => $order['mid'], 'prize_type' => $t['prize_type']));
  928. Dever::db('agent/order')->update(array('where_id' => $order['id'], 'prize_type' => $t['prize_type']));
  929. }
  930. # 检测有没有名额权益
  931. $prize_goods = Dever::db('setting/prize_goods')->select(array('prize_id' => $parent_prize['id']));
  932. if ($prize_goods) {
  933. # 赠送权益
  934. foreach ($prize_goods as $k1 => $v1) {
  935. $this->addGoods($parent_order, $v1, 1);
  936. }
  937. }
  938. $member = Dever::db('agent/member')->find($t['parent_mid']);
  939. if ($member) {
  940. $desc = $parent_prize['name'] . '名额使用';
  941. Dever::load('agent/lib/dhorder')->action($member, $parent_prize['name'], $parent_prize['num'], $parent_prize['price'], array(), -1, 2, 3, $parent_goods['type_id'], $desc);
  942. }
  943. }
  944. }
  945. }
  946. if (!isset($t['parent_level'])) {
  947. $t['parent_level'] = false;
  948. }
  949. if (!isset($t['child_num'])) {
  950. $t['child_num'] = 0;
  951. }
  952. $member = Dever::db('agent/member')->find($where['mid']);
  953. $desc = $member['name'] . '成为代理商,佣金'.$t['per'].'%';
  954. Dever::load('agent/lib/member')->up($member, $where['parent_mid'], $order['id'], $order['role'], $where['type'], $t['cash'], $order['agent_cash'], $t['parent_level'], $desc, $t['child_num']);
  955. # 自动升级
  956. if (isset($t['role_up']) && $t['role_up']) {
  957. $member = Dever::db('agent/member')->find(array('id' => $where['parent_mid']));
  958. $role = Dever::db('setting/role')->find($t['role_up']['t_role_id']);
  959. Dever::db('agent/member')->update(array('where_id' => $where['parent_mid'], 'role' => $t['role_up']['t_role_id']));
  960. if ($member && $role) {
  961. $this->upRole($member, $role, '', $order['id']);
  962. }
  963. }
  964. }
  965. }
  966. }
  967. private function setAgreement($order)
  968. {
  969. Dever::load('agent/lib/agreement')->up($order);
  970. }
  971. public function sellOrderUpdate($id, $name, $data)
  972. {
  973. Dever::config('base')->hook = true;
  974. $update = array();
  975. $audit = Dever::param('audit', $data);
  976. $desc = Dever::param('audit_desc', $data);
  977. $info = Dever::db('agent/dh_order')->one($id);
  978. if ($audit > 1 && $info && $info['status'] == 2) {
  979. if ($audit == 2) {
  980. # 成功
  981. Dever::setInput('order_id', $id);
  982. Dever::load('agent/lib/dhorder.audit_commit');
  983. } else {
  984. Dever::db('agent/dh_order')->update(array('where_id' => $id, 'status' => 7));
  985. Dever::load('agent/lib/dhorder')->updateSell($info, 2);
  986. if (Dever::project('sms')) {
  987. $member = Dever::db('agent/member')->find($info['mid']);
  988. Dever::load('sms/api')->send('daili_goods_no', $member['mobile'], array('name' => $member['name'], 'content' => $desc));
  989. }
  990. }
  991. }
  992. }
  993. public function sellOrderUpdateMul($id, $name, $data)
  994. {
  995. Dever::config('base')->hook = true;
  996. $status = Dever::param('status', $data);
  997. if ($status == 5) {
  998. $list = explode(',', $id);
  999. if ($list) {
  1000. foreach ($list as $k => $v) {
  1001. if (is_array($v)) {
  1002. $id = $v['id'];
  1003. $info = Dever::db('agent/dh_order')->one($id);
  1004. } else {
  1005. $id = $v;
  1006. $info = Dever::db('agent/dh_order')->one($id);
  1007. }
  1008. $info['status'] = 4;
  1009. Dever::load('agent/lib/dhorder')->finish($info, $info['shop_id']);
  1010. }
  1011. }
  1012. }
  1013. }
  1014. # 确认收货
  1015. public function setDhOrderStatus_api()
  1016. {
  1017. $order_id = Dever::input('order_id');
  1018. $info = Dever::db('agent/dh_order')->find($order_id);
  1019. if ($info) {
  1020. Dever::load('agent/lib/dhorder')->finish($info, $info['shop_id']);
  1021. return 'reload';
  1022. } else {
  1023. Dever::alert('错误的订单号');
  1024. }
  1025. }
  1026. # 获取权益名称
  1027. public function getGoods($type, $type_id, $sku_id, $name = '')
  1028. {
  1029. if ($type == 1) {
  1030. if ($name) {
  1031. return array('name' => $name . '('.$type_id.')');
  1032. }
  1033. if ($sku_id == -2) {
  1034. return '商品';
  1035. }
  1036. $goods_info = Dever::load('goods/lib/info')->getInfoBySku($type_id, $sku_id);
  1037. if (isset($goods_info['sku'])) {
  1038. $sku = '-' . $goods_info['sku']['string'];
  1039. } else {
  1040. $sku = '';
  1041. }
  1042. return array('name' => $goods_info['name'] . $sku . '('.$type_id.')', 'price' => $goods_info['price']);
  1043. } elseif ($type == 2) {
  1044. $code = Dever::db('card/code')->find($sku_id);
  1045. $card = Dever::db('card/info')->find($code['card_id']);
  1046. if ($name){
  1047. $card['name'] = $name;
  1048. }
  1049. return array('name' => $card['name'] . '('.$type_id.') <br /> ' . $code['card'], 'price' => $code['total_cash']);
  1050. } elseif ($type == 3) {
  1051. if ($name) {
  1052. return array('name' => $name . '('.$type_id.')');
  1053. }
  1054. $prize = Dever::db('setting/prize')->find($type_id);
  1055. return array('name' => $prize['name'] . '('.$type_id.')', 'price' => $prize['price']);
  1056. }
  1057. }
  1058. public function setOrderStatus_api()
  1059. {
  1060. $where['where_id'] = Dever::input('id');
  1061. $order = Dever::db('agent/order')->find($where['where_id']);
  1062. if ($order) {
  1063. $where['status'] = Dever::input('status');
  1064. if ($where['status'] == 6) {
  1065. $where['history_status'] = $order['status'];
  1066. }
  1067. Dever::db('agent/order')->update($where);
  1068. if ($where['status'] == 7) {
  1069. $data = Dever::db('agent/order')->getClose(array('mid' => $order['mid'], 'status' => 7, 'clear' => true));
  1070. if (!$data) {
  1071. # 关闭订单
  1072. $member = Dever::db('agent/member')->find($order['mid']);
  1073. if ($member) {
  1074. Dever::db('agent/member')->update(array('where_id' => $member['id'], 'state' => 2));
  1075. }
  1076. }
  1077. }
  1078. }
  1079. return 'reload';
  1080. }
  1081. public function upSignAgreement_api()
  1082. {
  1083. $id = Dever::input('id');
  1084. if ($id) {
  1085. Dever::load('agent/lib/agreement')->upContent($id, true);
  1086. }
  1087. return 'reload';
  1088. }
  1089. public function upAgreement_api()
  1090. {
  1091. $id = Dever::input('id');
  1092. if ($id) {
  1093. Dever::load('agent/lib/agreement')->upContent($id);
  1094. }
  1095. return 'reload';
  1096. }
  1097. public function dropAgreement_api()
  1098. {
  1099. $id = Dever::input('id');
  1100. if ($id) {
  1101. Dever::load('agent/lib/agreement')->drop($id);
  1102. }
  1103. return 'reload';
  1104. }
  1105. public function memberShop_api(){
  1106. $data = Dever::db('agent/member')->getShopAll(array('shop_id'=>1,'state'=>1));
  1107. if($data){
  1108. foreach($data as $k=>$v){
  1109. $log = Dever::db('agent/member_shop_log')->find(array('mid'=>$v['id']));
  1110. if($log){
  1111. }else{
  1112. Dever::db('agent/member_shop_log')->insert(array('mid'=>$v['id'],'new_shop_id'=>$v['shop_id'],'cdate'=>'1651680000'));
  1113. }
  1114. }
  1115. }
  1116. return 'ok';
  1117. }
  1118. public function updateUserBind($id, $name, $data)
  1119. {
  1120. Dever::config('base')->hook = true;
  1121. $update = array();
  1122. $audit = Dever::param('audit', $data);
  1123. $desc = Dever::param('audit_desc', $data);
  1124. $info = Dever::db('agent/user_bind')->one($id);
  1125. if ($info) {
  1126. if ($audit) {
  1127. $update['where_id'] = $info['id'];
  1128. $update['audit_date'] = time();
  1129. $update['status'] = $audit;
  1130. $admin = Dever::load('manage/auth.info');
  1131. $update['admin'] = $admin['id'];
  1132. Dever::db('agent/user_bind')->update($update);
  1133. }
  1134. }
  1135. }
  1136. public function search_api()
  1137. {
  1138. $where = array();
  1139. return Dever::search('agent/member', $where);
  1140. }
  1141. public function out_arealog($data){
  1142. $header = array('区域名称', '区域价值', '售出时间');
  1143. $body = array();
  1144. foreach($data as $k1=> $v1){
  1145. $member = Dever::db('agent/member')->find($v1['mid']);
  1146. $role = Dever::db('setting/role')->find($member['role']);
  1147. if ($role['type'] == 1) {
  1148. $data[$k1]['price'] = $role['price'];
  1149. }
  1150. if(isset($data[$k1]['price']) && $data[$k1]['price']<1){
  1151. unset($data[$k1]);
  1152. }
  1153. }
  1154. $res = array_values($data);
  1155. foreach($res as $k=>$v){
  1156. $res[$k]['areas'] = Dever::load("area/api.string", $v['area']);
  1157. $member = Dever::db('agent/member')->find($v['mid']);
  1158. $role = Dever::db('setting/role')->find($member['role']);
  1159. $res[$k]['cdate'] = date('Y-m-d H:i',$v['cdate']);
  1160. if ($role['type'] == 1) {
  1161. $res[$k]['price'] = $role['price'];
  1162. } elseif ($role['type'] == 2) {
  1163. $res[$k]['price'] = Dever::load('area/api')->getPrice($role['area'], $v['area']);
  1164. }
  1165. $d = array
  1166. (
  1167. $res[$k]['areas'],
  1168. $res[$k]['price'],
  1169. $res[$k]['cdate']
  1170. );
  1171. $body[] = $d;
  1172. }
  1173. $file = Dever::input('excel_name');
  1174. return Dever::excelExport($body, $header, $file);
  1175. }
  1176. public function out_zhitui($data){
  1177. $header = array('推荐人姓名', '手机号', '身份证', '角色', '被推荐人姓名', '手机号', '身份证', '角色','代理费','奖励金','时间');
  1178. $body = array();
  1179. foreach($data as $k => $v){
  1180. if($v['parent_mid']>0){
  1181. $member = Dever::db('agent/member')->find($v['parent_mid']);
  1182. $prole_name = '';
  1183. if($member && $member['role']){
  1184. $prole = Dever::db('setting/role')->find($member['role']);
  1185. if($prole && $prole['name']){
  1186. $prole_name = $prole['name'];
  1187. }
  1188. }
  1189. $role_name = '';
  1190. if($v['role']){
  1191. $role = Dever::db('setting/role') ->find($v['role']);
  1192. if($role && $role['name']){
  1193. $role_name = $role['name'];
  1194. }
  1195. }
  1196. $order = Dever::db('agent/order')->find(array('mid'=>$v['id']));
  1197. $cdate = '';
  1198. if($v['cdate']){
  1199. $cdate = date('Y-m-d H:i',$v['cdate']);
  1200. }
  1201. if($member){
  1202. $d = array
  1203. (
  1204. $member['name'],
  1205. $member['mobile'],
  1206. $member['idcard'],
  1207. $prole_name,
  1208. $v['name'],
  1209. $v['mobile'],
  1210. $v['idcard'],
  1211. $role['name'],
  1212. $order['agent_cash'],
  1213. $v['cash'],
  1214. $cdate,
  1215. );
  1216. $body[] = $d;
  1217. }
  1218. }
  1219. }
  1220. $file = Dever::input('excel_name');
  1221. return Dever::excelExport($body, $header, $file);
  1222. }
  1223. public function out_touxian($data){
  1224. $header = array('姓名', '手机号', '身份证', '角色', '头衔', '代理费', '直推姓名', '直推手机号', '直推身份证', '直推角色', '直推头衔', '推荐人姓名', '推荐人手机号', '推荐人身份证', '推荐人角色', '推荐人头衔', '注册时间', '终审时间', '月份');
  1225. $body = array();
  1226. foreach($data as $k => $v) {
  1227. if ($v['parent_mid'] > 0) {
  1228. $v['role_name'] = '';
  1229. if ($v['role']) {
  1230. $role = Dever::db('setting/role')->find($v['role']);
  1231. if($role && $role['name']) {
  1232. $v['role_name'] = $role['name'];
  1233. }
  1234. }
  1235. $v['title_name'] = '';
  1236. if ($v['title_id']) {
  1237. $title = Dever::db('setting/title')->getDataByIds(array('id' => $v['title_id']));
  1238. if($title) {
  1239. $v['title_name'] = array();
  1240. foreach ($title as $k1 => $v1) {
  1241. $v['title_name'][$v1['id']] = $v1['name'];
  1242. }
  1243. $v['title_name'] = implode('、', $v['title_name']);
  1244. }
  1245. }
  1246. $v['agent_cash'] = 0;
  1247. $order = Dever::db('agent/order')->getCount(array('mid'=>$v['id']));
  1248. if ($order) {
  1249. $v['agent_cash'] = $order['total'];
  1250. }
  1251. $month = '';
  1252. $udate = '';
  1253. #终审时间
  1254. if(isset($v['udate']) && $v['udate']) {
  1255. $month = date('m月',$v['udate']);
  1256. $month = preg_replace('/^0+/', '', $month);
  1257. $udate = date('Y-m-d H:i',$v['udate']);
  1258. }
  1259. #注册时间
  1260. $v['cdate'] = date('Y-m-d H:i',$v['cdate']);
  1261. $parent = Dever::db('agent/member')->find($v['parent_mid']);
  1262. if (!$parent) {
  1263. continue;
  1264. }
  1265. $parent['role_name'] = '';
  1266. if ($parent && $parent['role']) {
  1267. $role = Dever::db('setting/role')->find($parent['role']);
  1268. if ($role) {
  1269. $parent['role_name'] = $role['name'];
  1270. }
  1271. }
  1272. $group = array();
  1273. $parent['title_name'] = '';
  1274. if ($parent['title_id']) {
  1275. $title = Dever::db('setting/title')->getDataByIds(array('id' => $parent['title_id']));
  1276. if ($title) {
  1277. $parent['title_name'] = array();
  1278. foreach ($title as $k1 => $v1) {
  1279. $parent['title_name'][$v1['id']] = $v1['name'];
  1280. if ($v1['id'] == 2 || $v1['id'] == 3 || $v1['id'] == 9) {
  1281. $group = $parent;
  1282. $group['title_name'] = $v1['name'];
  1283. }
  1284. }
  1285. $parent['title_name'] = implode('、', $parent['title_name']);
  1286. }
  1287. }
  1288. if (!$group) {
  1289. $top = Dever::load('invite/api')->getParentAll($v['id'], 100);
  1290. if ($top) {
  1291. foreach ($top as $k1 => $v1) {
  1292. if ($v1['uid'] != $parent['id']) {
  1293. $p = Dever::db('agent/member')->one($v1['uid']);
  1294. if ($p && $p['title_id']) {
  1295. $t = explode(',', $p['title_id']);
  1296. if (in_array(2, $t)) {
  1297. $group = $p;
  1298. $group['title_name'] = '战略委';
  1299. $group['role_name'] = '';
  1300. if ($group['role']) {
  1301. $role = Dever::db('setting/role')->find($group['role']);
  1302. if ($role) {
  1303. $group['role_name'] = $role['name'];
  1304. }
  1305. }
  1306. break;
  1307. }
  1308. if (in_array(3, $t)) {
  1309. $group = $p;
  1310. $group['title_name'] = '决策委';
  1311. $group['role_name'] = '';
  1312. if ($group['role']) {
  1313. $role = Dever::db('setting/role')->find($group['role']);
  1314. if ($role) {
  1315. $group['role_name'] = $role['name'];
  1316. }
  1317. }
  1318. break;
  1319. }
  1320. if (in_array(9, $t)) {
  1321. $group = $p;
  1322. $group['title_name'] = '管理层';
  1323. $group['role_name'] = '';
  1324. if ($group['role']) {
  1325. $role = Dever::db('setting/role')->find($group['role']);
  1326. if ($role) {
  1327. $group['role_name'] = $role['name'];
  1328. }
  1329. }
  1330. break;
  1331. }
  1332. }
  1333. }
  1334. }
  1335. }
  1336. }
  1337. if (!$group) {
  1338. $group['name'] = $group['mobile'] = $group['idcard'] = $group['role_name'] = $group['title_name'] = '';
  1339. }
  1340. if($v){
  1341. $d = array
  1342. (
  1343. $v['name'],
  1344. $v['mobile'],
  1345. $v['idcard'],
  1346. $v['role_name'],
  1347. $v['title_name'],
  1348. $v['agent_cash'],
  1349. $parent['name'],
  1350. $parent['mobile'],
  1351. $parent['idcard'],
  1352. $parent['role_name'],
  1353. $parent['title_name'],
  1354. $group['name'],
  1355. $group['mobile'],
  1356. $group['idcard'],
  1357. $group['role_name'],
  1358. $group['title_name'],
  1359. $v['cdate'],
  1360. $udate,
  1361. $month,
  1362. );
  1363. $body[] = $d;
  1364. }
  1365. }
  1366. }
  1367. $file = Dever::input('excel_name');
  1368. return Dever::excelExport($body, $header, $file);
  1369. }
  1370. #新加期权业绩发放统计导出
  1371. public function out_member_cash($data)
  1372. {
  1373. $header = array('姓名','手机号','身份证号','角色','级别');
  1374. $year = date('Y',time());
  1375. if ($year == 2022) {
  1376. $m = 6;
  1377. $ym = 202206;
  1378. } elseif ($year >2022) {
  1379. $m = 1;
  1380. $ym = date('Ym',time());
  1381. }
  1382. for($i = $m; $i<=date('m',time()); $i++){
  1383. $month_config[]= $i.'月份业绩';
  1384. }
  1385. for ($i = $ym; $i<=date('Ym',time()); $i++) {
  1386. $month[] = $i.'01';
  1387. }
  1388. $header = array_merge($header,$month_config);
  1389. $body = array();
  1390. foreach ($data as $k => $v) {
  1391. $cash = Dever::db('bill/cash')->find(array('mid'=>$v['id']));
  1392. if ($cash) {
  1393. $role_name = '';
  1394. if (isset($v['role']) && $v['role']) {
  1395. $role = Dever::db('setting/role')->find($v['role']);
  1396. if ($role) {
  1397. $role_name = $role['name'];
  1398. }
  1399. }
  1400. $level_name = '';
  1401. if (isset($v['level_id']) && $v['level_id']) {
  1402. $level = Dever::db('setting/level')->find($v['level_id']);
  1403. if ($level) {
  1404. $level_name = $level['name'];
  1405. }
  1406. }
  1407. $d = array
  1408. (
  1409. $v['name'],
  1410. $v['mobile'],
  1411. $v['idcard'],
  1412. $role_name,
  1413. $level_name,
  1414. );
  1415. foreach ($month as $k1 => $v1) {
  1416. $w['mid'] = $v['id'];
  1417. $w['start'] = strtotime($v1);
  1418. $w['end'] = strtotime(date('Y-m-d',$w['start'])."+1 month - 1 day");
  1419. $w['type'] = '1,2';
  1420. $member_cash = Dever::db('bill/cash')->getMoney($w);
  1421. if ($member_cash && isset($member_cash['cash']) && $member_cash['cash']) {
  1422. $money = $member_cash['cash'];
  1423. } else {
  1424. $money = 0;
  1425. }
  1426. $d[] = $money;
  1427. }
  1428. $body[] = $d;;
  1429. }
  1430. }
  1431. $file = Dever::input('excel_name');
  1432. return Dever::excelExport($body, $header, $file);
  1433. }
  1434. public function out_order_touxian($data){
  1435. $header = array('姓名', '手机号', '身份证', '角色', '头衔', '代理费', '直推姓名', '直推手机号', '直推身份证', '直推角色', '直推头衔', '推荐人姓名', '推荐人手机号', '推荐人身份证', '推荐人角色', '推荐人头衔', '注册时间', '终审时间', '月份');
  1436. $body = array();
  1437. // print_R($data);die;
  1438. foreach($data as $k => $v) {
  1439. if ($v['parent_mid'] > 0) {
  1440. $v['role_name'] = '';
  1441. if ($v['role']) {
  1442. $role = Dever::db('setting/role')->find($v['role']);
  1443. if($role && $role['name']) {
  1444. $v['role_name'] = $role['name'];
  1445. }
  1446. }
  1447. $v['title_name'] = '';
  1448. $member = Dever::db('agent/member')->find($v['mid']);
  1449. if ($member && $member['title_id']) {
  1450. $title = Dever::db('setting/title')->getDataByIds(array('id' => $member['title_id']));
  1451. if($title) {
  1452. $v['title_name'] = array();
  1453. foreach ($title as $k1 => $v1) {
  1454. $v['title_name'][$v1['id']] = $v1['name'];
  1455. }
  1456. $v['title_name'] = implode('、', $v['title_name']);
  1457. }
  1458. }
  1459. // $v['agent_cash'] = 0;
  1460. // $order = Dever::db('agent/order')->getCount(array('mid'=>$v['id']));
  1461. // if ($order) {
  1462. // $v['agent_cash'] = $order['total'];
  1463. // }
  1464. $month = '';
  1465. $fdate = '';
  1466. #终审时间
  1467. if(isset($v['fdate']) && $v['fdate']) {
  1468. $month = date('m月',$v['fdate']);
  1469. $month = preg_replace('/^0+/', '', $month);
  1470. $fdate = date('Y-m-d H:i',$v['fdate']);
  1471. }
  1472. #注册时间
  1473. $v['cdate'] = date('Y-m-d H:i',$v['cdate']);
  1474. $parent = Dever::db('agent/member')->find($v['parent_mid']);
  1475. if (!$parent) {
  1476. continue;
  1477. }
  1478. $parent['role_name'] = '';
  1479. if ($parent && $parent['role']) {
  1480. $role = Dever::db('setting/role')->find($parent['role']);
  1481. if ($role) {
  1482. $parent['role_name'] = $role['name'];
  1483. }
  1484. }
  1485. $group = array();
  1486. $parent['title_name'] = '';
  1487. if ($parent['title_id']) {
  1488. $title = Dever::db('setting/title')->getDataByIds(array('id' => $parent['title_id']));
  1489. if ($title) {
  1490. $parent['title_name'] = array();
  1491. foreach ($title as $k1 => $v1) {
  1492. $parent['title_name'][$v1['id']] = $v1['name'];
  1493. if ($v1['id'] == 2 || $v1['id'] == 3 || $v1['id'] == 9) {
  1494. $group = $parent;
  1495. $group['title_name'] = $v1['name'];
  1496. }
  1497. }
  1498. $parent['title_name'] = implode('、', $parent['title_name']);
  1499. }
  1500. }
  1501. if (!$group) {
  1502. $top = Dever::load('invite/api')->getParentAll($v['id'], 100);
  1503. if ($top) {
  1504. foreach ($top as $k1 => $v1) {
  1505. if ($v1['uid'] != $parent['id']) {
  1506. $p = Dever::db('agent/member')->one($v1['uid']);
  1507. if ($p && $p['title_id']) {
  1508. $t = explode(',', $p['title_id']);
  1509. if (in_array(2, $t)) {
  1510. $group = $p;
  1511. $group['title_name'] = '战略委';
  1512. $group['role_name'] = '';
  1513. if ($group['role']) {
  1514. $role = Dever::db('setting/role')->find($group['role']);
  1515. if ($role) {
  1516. $group['role_name'] = $role['name'];
  1517. }
  1518. }
  1519. break;
  1520. }
  1521. if (in_array(3, $t)) {
  1522. $group = $p;
  1523. $group['title_name'] = '决策委';
  1524. $group['role_name'] = '';
  1525. if ($group['role']) {
  1526. $role = Dever::db('setting/role')->find($group['role']);
  1527. if ($role) {
  1528. $group['role_name'] = $role['name'];
  1529. }
  1530. }
  1531. break;
  1532. }
  1533. if (in_array(9, $t)) {
  1534. $group = $p;
  1535. $group['title_name'] = '管理层';
  1536. $group['role_name'] = '';
  1537. if ($group['role']) {
  1538. $role = Dever::db('setting/role')->find($group['role']);
  1539. if ($role) {
  1540. $group['role_name'] = $role['name'];
  1541. }
  1542. }
  1543. break;
  1544. }
  1545. }
  1546. }
  1547. }
  1548. }
  1549. }
  1550. if (!$group) {
  1551. $group['name'] = $group['mobile'] = $group['idcard'] = $group['role_name'] = $group['title_name'] = '';
  1552. }
  1553. if($v){
  1554. $d = array
  1555. (
  1556. $v['name'],
  1557. $v['mobile'],
  1558. $v['idcard'],
  1559. $v['role_name'],
  1560. $v['title_name'],
  1561. $v['agent_cash'],
  1562. $parent['name'],
  1563. $parent['mobile'],
  1564. $parent['idcard'],
  1565. $parent['role_name'],
  1566. $parent['title_name'],
  1567. $group['name'],
  1568. $group['mobile'],
  1569. $group['idcard'],
  1570. $group['role_name'],
  1571. $group['title_name'],
  1572. $v['cdate'],
  1573. $fdate,
  1574. $month,
  1575. );
  1576. $body[] = $d;
  1577. }
  1578. }
  1579. }
  1580. $file = Dever::input('excel_name');
  1581. return Dever::excelExport($body, $header, $file);
  1582. }
  1583. }