Manage.php 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766
  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. $log = Dever::db('agent/member_shop_log')->select($insert);
  350. if ($log) {
  351. foreach ($log as $k => $v) {
  352. Dever::db('agent/member_shop_log')->update(array('where_id' => $v['id'], 'status' => 2));
  353. }
  354. }
  355. $insert['new_shop_id'] = $shop_id;
  356. $insert['clear'] = true;
  357. $info = Dever::db('agent/member_shop_log')->find($insert);
  358. if (!$info) {
  359. $insert['old_shop_id'] = $member['shop_id'];
  360. $insert['status'] = 1;
  361. Dever::db('agent/member_shop_log')->insert($insert);
  362. } else {
  363. Dever::db('agent/member_shop_log')->update(array('where_id' => $info['id'], 'status' => 1));
  364. }
  365. }
  366. return $data;
  367. }
  368. # 更改日志
  369. private function upLog($member, $role, $area, $order_id = -1, $type = 3, $price = 0)
  370. {
  371. if (is_numeric($role)) {
  372. $role = Dever::db('setting/role')->find($role);
  373. }
  374. if (!$role) {
  375. return;
  376. }
  377. $this->upRole($member, $role, $area, $order_id);
  378. if ($area) {
  379. $this->upArea($member, $role, $area, $order_id, $type, $price);
  380. }
  381. }
  382. private function upRole($member, $role, $area, $order_id = -1)
  383. {
  384. if ($role['id'] == $member['role']) {
  385. return;
  386. }
  387. $data['mid'] = $member['id'];
  388. $data['order_id'] = $order_id;
  389. $data['old_role'] = $member['role'];
  390. $data['new_role'] = $role['id'];
  391. if ($area) {
  392. $data['area'] = $area;
  393. } else {
  394. $data['area'] = $member['area'];
  395. }
  396. if ($order_id && $order_id > 0) {
  397. $data['type'] = 1;
  398. $order = Dever::db('agent/order')->find($order_id);
  399. $data['price'] = $order['price'];
  400. } else {
  401. $data['type'] = 2;
  402. $admin = Dever::load('manage/auth.info');
  403. $data['audit_admin'] = $admin['id'];
  404. }
  405. Dever::db('agent/member_account_log')->insert($data);
  406. }
  407. public function upArea($member, $role, $area, $order_id = -1, $type = 3, $price = 0)
  408. {
  409. if (!$role) {
  410. return;
  411. }
  412. if ($area == $member['area']) {
  413. //return;
  414. }
  415. $area_data = array('mid' => $member['id']);
  416. $area_info = Dever::db('agent/member_area')->select($area_data);
  417. if ($area_info) {
  418. foreach ($area_info as $k => $v) {
  419. Dever::load('area/api')->upStatus($v['area'], 1);
  420. Dever::db('agent/member_area')->update(array('where_id' => $v['id'], 'state' => 2));
  421. }
  422. }
  423. if ($role && $role['type'] == 2) {
  424. Dever::load('area/api')->upStatus($area, 2);
  425. $area_data['order_id'] = $order_id;
  426. $area_data['role'] = $role['id'];
  427. $area_data['area'] = $area;
  428. $area_data['type'] = $type;
  429. $area_data['price'] = $price;
  430. $area_data['status'] = 1;
  431. Dever::db('agent/member_area')->insert($area_data);
  432. //Dever::load('agent/lib/order')->editArea($v, $area);
  433. }
  434. $this->area_log($member['id'], $order_id, $member['area'], $area);
  435. }
  436. # 获取
  437. # 设置上级
  438. public function setParent_commit($id, $name, $data)
  439. {
  440. //Dever::alert('暂未开放');
  441. Dever::config('base')->hook = true;
  442. $mid = Dever::param('mid', $data);
  443. $parent_mobile = trim(Dever::param('parent_mobile', $data));
  444. if ($mid && $parent_mobile) {
  445. $member = Dever::db('agent/member')->find($mid);
  446. $parent = Dever::db('agent/member')->find(array('mobile' => $parent_mobile));
  447. if ($parent && $parent['status'] == 2) {
  448. if ($member['parent_mid'] == $parent['id']) {
  449. Dever::alert('上级代理商设置失败');
  450. return;
  451. }
  452. if ($member['parent_mid'] == $mid) {
  453. Dever::alert('上级代理商不能设置为自己');
  454. return;
  455. }
  456. # 重置关系
  457. Dever::load('invite/api')->resetRelation($mid, $parent['id']);
  458. /*
  459. # 删除之前关系
  460. Dever::load('invite/api')->dropRelation($mid, $parent['id']);
  461. # 获取所有下级
  462. $child = Dever::load('invite/api')->getChild($mid);
  463. if ($child) {
  464. foreach ($child as $k => $v) {
  465. Dever::load('invite/api')->dropRelation($v['to_uid'], $parent['id']);
  466. }
  467. }
  468. # 重新设置关系
  469. Dever::load('invite/api')->setRelation($mid, $parent['id']);
  470. */
  471. Dever::db('agent/member')->update(array('where_id' => $mid, 'parent_mid' => $parent['id']));
  472. } else {
  473. Dever::alert('上级代理商还未注册或者已封禁');
  474. }
  475. }
  476. }
  477. public function orderUpdateParent($id, $name, $data)
  478. {
  479. Dever::config('base')->hook = true;
  480. $id = $id['where_id'];
  481. $order = Dever::db('agent/order')->find($id);
  482. if (!$order) {
  483. return;
  484. }
  485. $area = Dever::param('area', $data);#修改后
  486. $role = Dever::param('role', $data);
  487. $invite_type = Dever::param('invite_type', $data);
  488. $parent_code = Dever::param('parent_code', $data);
  489. if ($invite_type == 1 && $parent_code) {
  490. $parent_mid = Dever::load('invite/api')->getUid($parent_code);
  491. if ($parent_mid) {
  492. $parent_member = Dever::db('agent/member')->find($parent_mid);
  493. if (!$parent_member) {
  494. Dever::alert('错误的邀请码');
  495. }
  496. if ($order['mid'] == $parent_member['id']) {
  497. Dever::alert('邀请人不能是自己');
  498. }
  499. $data['set_parent_mid'] = $parent_mid;
  500. //Dever::db('agent/member')->update(array('where_id' => $order['mid'], 'parent_mid' => $parent_mid));
  501. } else {
  502. Dever::alert('错误的邀请码');
  503. }
  504. }
  505. if ($area && is_array($area) && $role) {
  506. $role = Dever::db('setting/role')->find($role);
  507. $area_string = array();
  508. if ($role && $role['type'] == 2) {
  509. $area_string = Dever::load('agent/lib/order')->checkArea($area, $role, $order['mid']);
  510. } else {
  511. $area_string = implode(',', $area);
  512. $area_string = str_replace(',-1', '', $area_string);
  513. }
  514. if ($role['type'] == 1) {
  515. $data['set_f_price'] = $data['set_price'] = $role['price'];
  516. } elseif ($role['type'] == 2) {
  517. $data['set_f_price'] = $data['set_price'] = Dever::load('area/api')->getPrice($role['area'], $area_string);
  518. } else {
  519. $data['set_f_price'] = $data['set_price'] = 0;
  520. }
  521. $data['set_area'] = $area_string;
  522. }
  523. return $data;
  524. }
  525. public function orderStartUpdate($id, $name, $data)
  526. {
  527. $order_id = Dever::param('order_id', $data);
  528. if ($order_id) {
  529. $order = Dever::db('agent/order')->find($order_id);
  530. if ($order) {
  531. $status = Dever::param('status', $data);
  532. if ($status) {
  533. $role = Dever::db('setting/role')->find($order['role']);
  534. if ($role && $role['type'] == 2) {
  535. Dever::load('agent/lib/order')->checkArea($order['area'], $role, $order['mid']);
  536. }
  537. }
  538. if ($order['source_id'] < 0) {
  539. if ($order['parent_mid'] > 0) {
  540. $member = Dever::db('agent/member')->find($order['parent_mid']);
  541. if ($member['status'] == 2) {
  542. return $data;
  543. }
  544. }
  545. Dever::alert('直属上级未认证,无法进行初审');
  546. }
  547. }
  548. }
  549. }
  550. public function orderUpdate($id, $name, $data)
  551. {
  552. Dever::config('base')->hook = true;
  553. $audit = Dever::param('audit', $data);
  554. $status = Dever::param('status', $data);
  555. $desc = Dever::param('desc', $data);
  556. $order_id = Dever::param('order_id', $data);
  557. $order = Dever::db('agent/order')->find($order_id);
  558. if ($order_id && $order && $status) {
  559. $admin = Dever::load('manage/auth.info');
  560. if ($admin) {
  561. Dever::db('agent/order_process')->update(array('where_id' => $id, 'admin' => $admin['id']));
  562. }
  563. if ($status < 3) {
  564. if ($audit == 1) {
  565. $update = array('where_id' => $order_id, 'status' => $status+1);
  566. if ($status == 1) {
  567. $soft_price = Dever::param('soft_price', $data);
  568. $price = Dever::param('price', $data);
  569. $prize_type = Dever::param('prize_type', $data);
  570. $option_price = Dever::param('option_price', $data);
  571. if ($prize_type == 2) {
  572. # 扣减已有名额,判断一下 暂时废弃
  573. $prize = Dever::db('setting/prize')->find(array('type' => 1, 'price' => $order['price']));
  574. if ($prize) {
  575. $member_goods = Dever::db('agent/member_goods')->getOne(array('mid' => $order['mid'], 'type' => 3, 'type_id' => $prize['id']));
  576. if ($member_goods && $member_goods['num'] > 0) {
  577. # 有名额
  578. $price = 0;
  579. # 开始扣减
  580. $member = Dever::db('agent/member')->find($order['mid']);
  581. Dever::load('agent/lib/dhorder')->action($member, $prize['name'], $prize['num'], $prize['price'], array(), -1, 2, 3, $prize['id'], $desc);
  582. }
  583. }
  584. }
  585. if ($price <= 0) {
  586. $update['get_type'] = 2;
  587. } else {
  588. $update['get_type'] = 1;
  589. }
  590. $update['price'] = $price;
  591. $update['agent_cash'] = $price;
  592. $update['soft_cash'] = 0;
  593. $update['option_price']=$option_price;
  594. $cstatus = Dever::param('cstatus', $data);
  595. if ($cstatus && $cstatus == 2 && $price > 0) {
  596. # 拆分代理费
  597. if ($soft_price > 0) {
  598. $update['agent_cash'] = $price - $soft_price;
  599. $update['soft_cash'] = $soft_price;
  600. } else {
  601. $role = Dever::db('setting/role')->one($order['role']);
  602. if ($role && $role['soft']) {
  603. if (strstr($role['soft'], '%')) {
  604. $role['soft'] = str_replace('%', '', $role['soft']);
  605. $role['soft'] = $price * ($role['soft']/100);
  606. }
  607. $update['agent_cash'] = $price - $role['soft'];
  608. $update['soft_cash'] = $role['soft'];
  609. }
  610. }
  611. }
  612. # 增加业绩
  613. //Dever::load('bill/lib/sell')->up($order['mid'], 2, $order['price'], $order['role'], $order['id'], $order['name'] . '成为代理商');
  614. } elseif ($status == 2) {
  615. if ($order['mid'] && $order['mid'] > 0 && $order['parent_mid'] && $order['parent_mid'] > 0) {
  616. Dever::load('invite/api')->setRelation($order['mid'], $order['parent_mid']);
  617. Dever::db('agent/member')->update(array('where_id' => $order['mid'], 'parent_mid' => $order['parent_mid']));
  618. }
  619. $update['pay_status'] = 2;
  620. Dever::load('agent/lib/member')->create($order);
  621. }
  622. Dever::db('agent/order')->update($update);
  623. } else {
  624. Dever::db('agent/order')->update(array('where_id' => $order_id, 'status' => 5, 'history_status' => $order['status'], 'audit_desc' => $desc));
  625. if (Dever::project('sms')) {
  626. Dever::load('sms/api')->send('daili_reg_no', $order['mobile'], array('name' => $order['name'], 'content' => $desc));
  627. }
  628. }
  629. } elseif ($status == 3) {
  630. $info = Dever::db('agent/order_process')->find(array('id' => $id, 'clear' => true));
  631. if ($info && $info['status'] == 3) {
  632. $info['type'] = explode(',', $info['type']);
  633. }
  634. if (in_array(2, $info['type'])) {
  635. $goods_status = 3;
  636. } else {
  637. $goods_status = 2;
  638. }
  639. $curtime = time();
  640. Dever::db('agent/order')->update(array('where_id' => $order_id, 'fdate' => $curtime, 'status' => 4, 'goods_status' => $goods_status));
  641. # 通知短信
  642. if (Dever::project('sms')) {
  643. $order = Dever::db('agent/order')->find($order_id);
  644. Dever::load('sms/api')->send('daili_reg_yes', $order['mobile'], array('name' => $order['name']));
  645. }
  646. $order = Dever::db('agent/order')->find($order_id);
  647. if ($order && $order['mid']) {
  648. $member = Dever::db('agent/member')->find($order['mid']);
  649. $update['where_id'] = $order['mid'];
  650. if ($member && $member['status'] == 1) {
  651. $update['status'] = 2;
  652. $update['rdate'] = $curtime;
  653. }
  654. $update['area'] = $order['area'];
  655. $update['role'] = $order['role'];
  656. $update['udate'] = $curtime;
  657. Dever::db('agent/member')->update($update);
  658. if ($order['price'] > 0) {
  659. $type = 1;
  660. } else {
  661. $type = 2;
  662. }
  663. $this->upLog($member, $order['role'], $order['area'], $order['id'], $type, $order['price']);
  664. }
  665. }
  666. }
  667. }
  668. #区域日志
  669. public function area_log($mid,$order_id,$old_area, $area) {
  670. $data['mid']=$mid;
  671. $data['order_id']=$order_id;
  672. $data['old_area']=$old_area;
  673. $data['area']=$area;
  674. if ($order_id && $order_id > 0) {
  675. $data['type'] = 1;
  676. } else {
  677. $admin = Dever::load('manage/auth.info');
  678. $data['audit_admin'] = $admin['id'];
  679. $data['type'] = 2;
  680. }
  681. $id = Dever::db('agent/member_area_log')->insert($data);
  682. return $id;
  683. }
  684. # 发放权益
  685. public function set_commit_api()
  686. {
  687. Dever::config('base')->hook = true;
  688. $type = Dever::input('type', 2);
  689. $order_id = Dever::input('order_id');
  690. # 检测是否发放过了
  691. $order = Dever::db('agent/order')->find($order_id);
  692. if ($order['status'] != 3) {
  693. //Dever::alert('无发放权限');
  694. }
  695. $order_process = Dever::db('agent/order_process')->find(array('order_id' => $order_id, 'status' => 3));
  696. $yes = -1;
  697. if (!$order_process) {
  698. # 可以发放
  699. $yes = 1;
  700. } elseif ($order_process) {
  701. $order_process['type'] = explode(',', $order_process['type']);
  702. if (!in_array($type, $order_process['type'])) {
  703. # 可以发放
  704. $yes = 2;
  705. }
  706. }
  707. if ($yes > 0) {
  708. if ($yes == 1) {
  709. $data['order_id'] = $order_id;
  710. $data['status'] = 3;
  711. $data['type'] = '1,' . $type;
  712. $state = Dever::db('agent/order_process')->insert($data);
  713. } else {
  714. $data['where_id'] = $order_process['id'];
  715. $order_process['type'][] = $type;
  716. $data['type'] = implode(',', $order_process['type']);
  717. $state = Dever::db('agent/order_process')->update($data);
  718. }
  719. if ($state) {
  720. if ($type == 2) {
  721. $this->setGoods($order);
  722. } elseif ($type == 3) {
  723. $this->setCash($order);
  724. } elseif ($type == 5) {
  725. $this->setAgreement($order);
  726. }
  727. }
  728. return 'reload';
  729. } else {
  730. Dever::alert('无发放权限');
  731. }
  732. }
  733. # 设置多个权益
  734. private function setGoods($order)
  735. {
  736. $t = 1;
  737. $goods = Dever::db('agent/order_goods')->getData(array('order_id' => $order['id']));
  738. if (!$goods) {
  739. $goods = Dever::db('setting/role_goods')->getData(array('role_id' => $order['role'], 'give' => $order['order_type']));
  740. $t = intval($order['agent_cash']/10000);
  741. if ($t <= 0) {
  742. $t = 1;
  743. }
  744. }
  745. if ($goods) {
  746. $where = array();
  747. $goods_cash = 0;
  748. foreach ($goods as $k => $v) {
  749. $order_goods = array();
  750. $order_goods['order_id'] = $order['id'];
  751. $order_goods['type'] = $v['type'];
  752. $order_goods['type_id'] = $v['type_id'];
  753. $order_goods['sku_id'] = $v['sku_id'];
  754. $order_goods['num'] = $v['num'];
  755. Dever::db('agent/order_goods')->insert($order_goods);
  756. $price = $this->addGoods($order, $v, $t);
  757. if ($price && $v['type'] < 3) {
  758. # 计算商品价值
  759. $goods_cash += $price;
  760. }
  761. }
  762. $update = array();
  763. if ($goods_cash) {
  764. $update['goods_cash'] = $goods_cash;
  765. }
  766. $update['goods_status'] = 3;
  767. $update['where_id'] = $order['id'];
  768. Dever::db('agent/order')->update($update);
  769. }
  770. }
  771. # 新增权益
  772. private function addGoods($order, $v, $t)
  773. {
  774. $cash = $price = 0;
  775. if ($v['type'] == 1) {
  776. $v['num'] = $v['num'] * $t;
  777. $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v['type_id'], $v['sku_id']);
  778. $price = $goods_info['price'];
  779. $cash = $goods_info['price'] * $v['num'];
  780. if (isset($goods_info['sku'])) {
  781. $sku = '-' . $goods_info['sku']['string'];
  782. } else {
  783. $sku = '';
  784. }
  785. $name = $goods_info['name'] . $sku;
  786. } elseif ($v['type'] == 2) {
  787. $v['sku_id'] = -1;
  788. # 生成一个电子券
  789. $card = Dever::db('card/info')->find($v['type_id']);
  790. if (!$card) {
  791. return false;
  792. }
  793. $name = $card['name'];
  794. if ($card['create_type'] == 2) {
  795. $cash = $card['value']*$v['num'] * $t;
  796. $price = $cash;
  797. $v['num'] = 1;
  798. $v['sku_id'] = Dever::load('card/lib/code')->create($card, 2, $order['mid'], $order['id'], $cash);
  799. if (!$v['sku_id']) {
  800. return false;
  801. }
  802. } elseif ($card['create_type'] == 3) {
  803. $cash = round($order['agent_cash']*($v['num']/100), 2);
  804. $price = $cash;
  805. $v['num'] = 1;
  806. $v['sku_id'] = Dever::load('card/lib/code')->create($card, 2, $order['mid'], $order['id'], $cash);
  807. if (!$v['sku_id']) {
  808. return false;
  809. }
  810. } else {
  811. $cash = $card['value'];
  812. $price = $cash;
  813. $total = $t*$v['num'];
  814. $t = 1;
  815. for($i=0; $i<$total;$i++) {
  816. $v['sku_id'] = Dever::load('card/lib/code')->create($card, 2, $order['mid'], $order['id'], $cash);
  817. if ($v['sku_id']) {
  818. $where['mid'] = $order['mid'];
  819. $where['type'] = $v['type'];
  820. $where['type_id'] = $v['type_id'];
  821. $where['sku_id'] = $v['sku_id'];
  822. $info = Dever::db('agent/member_goods')->find($where);
  823. if (!$info) {
  824. $up = $where;
  825. $up['total_num'] = $t;
  826. $up['cash'] = $cash;
  827. $up['price'] = $price;
  828. $up['name'] = $name;
  829. $state = Dever::db('agent/member_goods')->insert($up);
  830. if ($state) {
  831. Dever::load('agent/lib/member_set')->log($order['mid'], $order['order_num'], $v['type'], $v['type_id'], $v['sku_id'], $t, 0, $t, $name);
  832. }
  833. }
  834. }
  835. }
  836. return $cash * $total;
  837. }
  838. } elseif ($v['type'] == 3) {
  839. $prize = Dever::db('setting/prize')->find($v['type_id']);
  840. $v['num'] = $v['num'] * $t;
  841. $role = Dever::db('setting/role')->find($order['role']);
  842. if ($role && $role['max_me_num'] && $role['max_me_num'] < $v['num']) {
  843. $v['num'] = $role['max_me_num'];
  844. }
  845. $price = $prize['price'];
  846. $cash = $prize['price']*$v['num'];
  847. $name = $prize['name'];
  848. }
  849. $where['mid'] = $order['mid'];
  850. $where['type'] = $v['type'];
  851. $where['type_id'] = $v['type_id'];
  852. $where['sku_id'] = $v['sku_id'];
  853. $info = Dever::db('agent/member_goods')->find($where);
  854. if ($info) {
  855. $up['where_id'] = $info['id'];
  856. $up['total_num'] = $info['total_num'] + $v['num'];
  857. $up['cash'] = $cash;
  858. $up['price'] = $price;
  859. $up['name'] = $name;
  860. $state = Dever::db('agent/member_goods')->update($up);
  861. if ($state) {
  862. 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);
  863. }
  864. } else {
  865. $up = $where;
  866. $up['total_num'] = $v['num'];
  867. $up['cash'] = $cash;
  868. $up['price'] = $price;
  869. $up['name'] = $name;
  870. $state = Dever::db('agent/member_goods')->insert($up);
  871. if ($state) {
  872. 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);
  873. }
  874. }
  875. return $cash;
  876. }
  877. private function setCash($order)
  878. {
  879. $param = Dever::input('param');
  880. if ($param) {
  881. $param = explode(',', $param);
  882. foreach ($param as $k => $v) {
  883. $t = Dever::array_decode($v);
  884. $parent_order = $order;
  885. $parent_order['mid'] = $t['parent_mid'];
  886. $where['type'] = $t['type'];
  887. $where['order_id'] = $order['id'];
  888. $where['mid'] = $order['mid'];
  889. $where['parent_mid'] = $t['parent_mid'];
  890. $info = Dever::db('agent/order_cash')->find($where);
  891. if (!$info) {
  892. $insert = $where;
  893. $insert['cash'] = $t['cash'];
  894. $insert['per'] = $t['per'];
  895. if (isset($t['prize_id'])) {
  896. $insert['prize_id'] = $t['prize_id'];
  897. }
  898. if (isset($t['goods'])) {
  899. $insert['goods'] = Dever::array_encode($t['goods']);
  900. }
  901. Dever::db('agent/order_cash')->insert($insert);
  902. } else {
  903. $update['where_id'] = $info['id'];
  904. $update['cash'] = $t['cash'];
  905. $update['per'] = $t['per'];
  906. if (isset($t['prize_id'])) {
  907. $update['prize_id'] = $t['prize_id'];
  908. }
  909. if (isset($t['goods'])) {
  910. $update['goods'] = Dever::array_encode($t['goods']);
  911. }
  912. Dever::db('agent/order_cash')->update($update);
  913. }
  914. if (isset($t['prize_id']) && isset($t['child_num'])) {
  915. $prize_info = Dever::db('setting/prize')->find($t['prize_id']);
  916. if ($prize_info) {
  917. $prize_insert['order_id'] = $order['order_id'];
  918. $prize_insert['mid'] = $t['parent_mid'];
  919. $prize_insert['child_num'] = $t['child_num'];
  920. $prize_insert['prize_id'] = $prize_info['id'];
  921. Dever::db('agent/member_prize')->insert($prize_insert);
  922. $prize['type'] = 3;
  923. $prize['type_id'] = $prize_info['id'];
  924. $prize['sku_id'] = -1;
  925. $prize['num'] = $prize_info['num'];
  926. $this->addGoods($parent_order, $prize, 1);
  927. }
  928. }
  929. if (isset($t['parent_goods_id'])) {
  930. $parent_goods = Dever::db('agent/member_goods')->getOne(array('id' => $t['parent_goods_id']));
  931. if ($parent_goods && $parent_goods['num'] > 0) {
  932. $parent_prize = Dever::db('setting/prize')->find($parent_goods['type_id']);
  933. if ($parent_prize) {
  934. # 判断是否名额内
  935. if (isset($t['prize_type']) && $t['prize_type'] == 2) {
  936. Dever::db('agent/member')->update(array('where_id' => $order['mid'], 'prize_type' => $t['prize_type']));
  937. Dever::db('agent/order')->update(array('where_id' => $order['id'], 'prize_type' => $t['prize_type']));
  938. }
  939. # 检测有没有名额权益
  940. $prize_goods = Dever::db('setting/prize_goods')->select(array('prize_id' => $parent_prize['id']));
  941. if ($prize_goods) {
  942. # 赠送权益
  943. foreach ($prize_goods as $k1 => $v1) {
  944. $this->addGoods($parent_order, $v1, 1);
  945. }
  946. }
  947. $member = Dever::db('agent/member')->find($t['parent_mid']);
  948. if ($member) {
  949. $desc = $parent_prize['name'] . '名额使用';
  950. 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);
  951. }
  952. }
  953. }
  954. }
  955. if (!isset($t['parent_level'])) {
  956. $t['parent_level'] = false;
  957. }
  958. if (!isset($t['child_num'])) {
  959. $t['child_num'] = 0;
  960. }
  961. $member = Dever::db('agent/member')->find($where['mid']);
  962. $desc = $member['name'] . '成为代理商,佣金'.$t['per'].'%';
  963. 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']);
  964. # 自动升级
  965. if (isset($t['role_up']) && $t['role_up']) {
  966. $member = Dever::db('agent/member')->find(array('id' => $where['parent_mid']));
  967. $role = Dever::db('setting/role')->find($t['role_up']['t_role_id']);
  968. Dever::db('agent/member')->update(array('where_id' => $where['parent_mid'], 'role' => $t['role_up']['t_role_id']));
  969. if ($member && $role) {
  970. $this->upRole($member, $role, '', $order['id']);
  971. }
  972. }
  973. }
  974. }
  975. }
  976. private function setAgreement($order)
  977. {
  978. Dever::load('agent/lib/agreement')->up($order);
  979. }
  980. public function sellOrderUpdate($id, $name, $data)
  981. {
  982. Dever::config('base')->hook = true;
  983. $update = array();
  984. $audit = Dever::param('audit', $data);
  985. $desc = Dever::param('audit_desc', $data);
  986. $info = Dever::db('agent/dh_order')->one($id);
  987. if ($audit > 1 && $info && $info['status'] == 2) {
  988. if ($audit == 2) {
  989. # 成功
  990. Dever::setInput('order_id', $id);
  991. Dever::load('agent/lib/dhorder.audit_commit');
  992. } else {
  993. Dever::db('agent/dh_order')->update(array('where_id' => $id, 'status' => 7));
  994. Dever::load('agent/lib/dhorder')->updateSell($info, 2);
  995. if (Dever::project('sms')) {
  996. $member = Dever::db('agent/member')->find($info['mid']);
  997. Dever::load('sms/api')->send('daili_goods_no', $member['mobile'], array('name' => $member['name'], 'content' => $desc));
  998. }
  999. }
  1000. }
  1001. }
  1002. public function sellOrderUpdateMul($id, $name, $data)
  1003. {
  1004. Dever::config('base')->hook = true;
  1005. $status = Dever::param('status', $data);
  1006. if ($status == 5) {
  1007. $list = explode(',', $id);
  1008. if ($list) {
  1009. foreach ($list as $k => $v) {
  1010. if (is_array($v)) {
  1011. $id = $v['id'];
  1012. $info = Dever::db('agent/dh_order')->one($id);
  1013. } else {
  1014. $id = $v;
  1015. $info = Dever::db('agent/dh_order')->one($id);
  1016. }
  1017. $info['status'] = 4;
  1018. Dever::load('agent/lib/dhorder')->finish($info, $info['shop_id']);
  1019. }
  1020. }
  1021. }
  1022. }
  1023. # 确认收货
  1024. public function setDhOrderStatus_api()
  1025. {
  1026. $order_id = Dever::input('order_id');
  1027. $info = Dever::db('agent/dh_order')->find($order_id);
  1028. if ($info) {
  1029. Dever::load('agent/lib/dhorder')->finish($info, $info['shop_id']);
  1030. return 'reload';
  1031. } else {
  1032. Dever::alert('错误的订单号');
  1033. }
  1034. }
  1035. # 获取权益名称
  1036. public function getGoods($type, $type_id, $sku_id, $name = '')
  1037. {
  1038. if ($type == 1) {
  1039. if ($name) {
  1040. return array('name' => $name . '('.$type_id.')');
  1041. }
  1042. if ($sku_id == -2) {
  1043. return '商品';
  1044. }
  1045. $goods_info = Dever::load('goods/lib/info')->getInfoBySku($type_id, $sku_id);
  1046. if (isset($goods_info['sku'])) {
  1047. $sku = '-' . $goods_info['sku']['string'];
  1048. } else {
  1049. $sku = '';
  1050. }
  1051. return array('name' => $goods_info['name'] . $sku . '('.$type_id.')', 'price' => $goods_info['price']);
  1052. } elseif ($type == 2) {
  1053. $code = Dever::db('card/code')->find($sku_id);
  1054. $card = Dever::db('card/info')->find($code['card_id']);
  1055. if ($name){
  1056. $card['name'] = $name;
  1057. }
  1058. return array('name' => $card['name'] . '('.$type_id.') <br /> ' . $code['card'], 'price' => $code['total_cash']);
  1059. } elseif ($type == 3) {
  1060. if ($name) {
  1061. return array('name' => $name . '('.$type_id.')');
  1062. }
  1063. $prize = Dever::db('setting/prize')->find($type_id);
  1064. return array('name' => $prize['name'] . '('.$type_id.')', 'price' => $prize['price']);
  1065. }
  1066. }
  1067. public function setOrderStatus_api()
  1068. {
  1069. $where['where_id'] = Dever::input('id');
  1070. $order = Dever::db('agent/order')->find($where['where_id']);
  1071. if ($order) {
  1072. $where['status'] = Dever::input('status');
  1073. if ($where['status'] == 6) {
  1074. $where['history_status'] = $order['status'];
  1075. }
  1076. Dever::db('agent/order')->update($where);
  1077. if ($where['status'] == 7) {
  1078. $data = Dever::db('agent/order')->getClose(array('mid' => $order['mid'], 'status' => 7, 'clear' => true));
  1079. if (!$data) {
  1080. # 关闭订单
  1081. $member = Dever::db('agent/member')->find($order['mid']);
  1082. if ($member) {
  1083. Dever::db('agent/member')->update(array('where_id' => $member['id'], 'state' => 2));
  1084. }
  1085. }
  1086. }
  1087. }
  1088. return 'reload';
  1089. }
  1090. public function upSignAgreement_api()
  1091. {
  1092. $id = Dever::input('id');
  1093. if ($id) {
  1094. Dever::load('agent/lib/agreement')->upContent($id, true);
  1095. }
  1096. return 'reload';
  1097. }
  1098. public function upAgreement_api()
  1099. {
  1100. $id = Dever::input('id');
  1101. if ($id) {
  1102. Dever::load('agent/lib/agreement')->upContent($id);
  1103. }
  1104. return 'reload';
  1105. }
  1106. public function dropAgreement_api()
  1107. {
  1108. $id = Dever::input('id');
  1109. if ($id) {
  1110. Dever::load('agent/lib/agreement')->drop($id);
  1111. }
  1112. return 'reload';
  1113. }
  1114. public function memberShop_api(){
  1115. $data = Dever::db('agent/member')->getShopAll(array('shop_id'=>1,'state'=>1));
  1116. if($data){
  1117. foreach($data as $k=>$v){
  1118. $log = Dever::db('agent/member_shop_log')->find(array('mid'=>$v['id']));
  1119. if($log){
  1120. }else{
  1121. Dever::db('agent/member_shop_log')->insert(array('mid'=>$v['id'],'new_shop_id'=>$v['shop_id'],'cdate'=>'1651680000'));
  1122. }
  1123. }
  1124. }
  1125. return 'ok';
  1126. }
  1127. public function updateUserBind($id, $name, $data)
  1128. {
  1129. Dever::config('base')->hook = true;
  1130. $update = array();
  1131. $audit = Dever::param('audit', $data);
  1132. $desc = Dever::param('audit_desc', $data);
  1133. $info = Dever::db('agent/user_bind')->one($id);
  1134. if ($info) {
  1135. if ($audit) {
  1136. $update['where_id'] = $info['id'];
  1137. $update['audit_date'] = time();
  1138. $update['status'] = $audit;
  1139. $admin = Dever::load('manage/auth.info');
  1140. $update['admin'] = $admin['id'];
  1141. Dever::db('agent/user_bind')->update($update);
  1142. }
  1143. }
  1144. }
  1145. public function search_api()
  1146. {
  1147. $where = array();
  1148. return Dever::search('agent/member', $where);
  1149. }
  1150. public function out_arealog($data){
  1151. $header = array('区域名称', '区域价值', '售出时间');
  1152. $body = array();
  1153. foreach($data as $k1=> $v1){
  1154. $member = Dever::db('agent/member')->find($v1['mid']);
  1155. $role = Dever::db('setting/role')->find($member['role']);
  1156. if ($role['type'] == 1) {
  1157. $data[$k1]['price'] = $role['price'];
  1158. }
  1159. if(isset($data[$k1]['price']) && $data[$k1]['price']<1){
  1160. unset($data[$k1]);
  1161. }
  1162. }
  1163. $res = array_values($data);
  1164. foreach($res as $k=>$v){
  1165. $res[$k]['areas'] = Dever::load("area/api.string", $v['area']);
  1166. $member = Dever::db('agent/member')->find($v['mid']);
  1167. $role = Dever::db('setting/role')->find($member['role']);
  1168. $res[$k]['cdate'] = date('Y-m-d H:i',$v['cdate']);
  1169. if ($role['type'] == 1) {
  1170. $res[$k]['price'] = $role['price'];
  1171. } elseif ($role['type'] == 2) {
  1172. $res[$k]['price'] = Dever::load('area/api')->getPrice($role['area'], $v['area']);
  1173. }
  1174. $d = array
  1175. (
  1176. $res[$k]['areas'],
  1177. $res[$k]['price'],
  1178. $res[$k]['cdate']
  1179. );
  1180. $body[] = $d;
  1181. }
  1182. $file = Dever::input('excel_name');
  1183. return Dever::excelExport($body, $header, $file);
  1184. }
  1185. public function out_zhitui($data){
  1186. $header = array('推荐人姓名', '手机号', '身份证', '角色', '被推荐人姓名', '手机号', '身份证', '角色','代理费','奖励金','时间');
  1187. $body = array();
  1188. foreach($data as $k => $v){
  1189. if($v['parent_mid']>0){
  1190. $member = Dever::db('agent/member')->find($v['parent_mid']);
  1191. $prole_name = '';
  1192. if($member && $member['role']){
  1193. $prole = Dever::db('setting/role')->find($member['role']);
  1194. if($prole && $prole['name']){
  1195. $prole_name = $prole['name'];
  1196. }
  1197. }
  1198. $role_name = '';
  1199. if($v['role']){
  1200. $role = Dever::db('setting/role') ->find($v['role']);
  1201. if($role && $role['name']){
  1202. $role_name = $role['name'];
  1203. }
  1204. }
  1205. $order = Dever::db('agent/order')->find(array('mid'=>$v['id']));
  1206. $cdate = '';
  1207. if($v['cdate']){
  1208. $cdate = date('Y-m-d H:i',$v['cdate']);
  1209. }
  1210. if($member){
  1211. $d = array
  1212. (
  1213. $member['name'],
  1214. $member['mobile'],
  1215. $member['idcard'],
  1216. $prole_name,
  1217. $v['name'],
  1218. $v['mobile'],
  1219. $v['idcard'],
  1220. $role['name'],
  1221. $order['agent_cash'],
  1222. $v['cash'],
  1223. $cdate,
  1224. );
  1225. $body[] = $d;
  1226. }
  1227. }
  1228. }
  1229. $file = Dever::input('excel_name');
  1230. return Dever::excelExport($body, $header, $file);
  1231. }
  1232. public function out_touxian($data){
  1233. $header = array('姓名', '手机号', '身份证', '角色', '头衔', '代理费', '直推姓名', '直推手机号', '直推身份证', '直推角色', '直推头衔', '推荐人姓名', '推荐人手机号', '推荐人身份证', '推荐人角色', '推荐人头衔', '注册时间', '终审时间', '月份');
  1234. $body = array();
  1235. foreach($data as $k => $v) {
  1236. if ($v['parent_mid'] > 0) {
  1237. $v['role_name'] = '';
  1238. if ($v['role']) {
  1239. $role = Dever::db('setting/role')->find($v['role']);
  1240. if($role && $role['name']) {
  1241. $v['role_name'] = $role['name'];
  1242. }
  1243. }
  1244. $v['title_name'] = '';
  1245. if ($v['title_id']) {
  1246. $title = Dever::db('setting/title')->getDataByIds(array('id' => $v['title_id']));
  1247. if($title) {
  1248. $v['title_name'] = array();
  1249. foreach ($title as $k1 => $v1) {
  1250. $v['title_name'][$v1['id']] = $v1['name'];
  1251. }
  1252. $v['title_name'] = implode('、', $v['title_name']);
  1253. }
  1254. }
  1255. $v['agent_cash'] = 0;
  1256. $order = Dever::db('agent/order')->getCount(array('mid'=>$v['id']));
  1257. if ($order) {
  1258. $v['agent_cash'] = $order['total'];
  1259. }
  1260. $month = '';
  1261. $udate = '';
  1262. #终审时间
  1263. if(isset($v['udate']) && $v['udate']) {
  1264. $month = date('m月',$v['udate']);
  1265. $month = preg_replace('/^0+/', '', $month);
  1266. $udate = date('Y-m-d H:i',$v['udate']);
  1267. }
  1268. #注册时间
  1269. $v['cdate'] = date('Y-m-d H:i',$v['cdate']);
  1270. $parent = Dever::db('agent/member')->find($v['parent_mid']);
  1271. if (!$parent) {
  1272. continue;
  1273. }
  1274. $parent['role_name'] = '';
  1275. if ($parent && $parent['role']) {
  1276. $role = Dever::db('setting/role')->find($parent['role']);
  1277. if ($role) {
  1278. $parent['role_name'] = $role['name'];
  1279. }
  1280. }
  1281. $group = array();
  1282. $parent['title_name'] = '';
  1283. if ($parent['title_id']) {
  1284. $title = Dever::db('setting/title')->getDataByIds(array('id' => $parent['title_id']));
  1285. if ($title) {
  1286. $parent['title_name'] = array();
  1287. foreach ($title as $k1 => $v1) {
  1288. $parent['title_name'][$v1['id']] = $v1['name'];
  1289. if ($v1['id'] == 2 || $v1['id'] == 3 || $v1['id'] == 9) {
  1290. $group = $parent;
  1291. $group['title_name'] = $v1['name'];
  1292. }
  1293. }
  1294. $parent['title_name'] = implode('、', $parent['title_name']);
  1295. }
  1296. }
  1297. if (!$group) {
  1298. $top = Dever::load('invite/api')->getParentAll($v['id'], 100);
  1299. if ($top) {
  1300. foreach ($top as $k1 => $v1) {
  1301. if ($v1['uid'] != $parent['id']) {
  1302. $p = Dever::db('agent/member')->one($v1['uid']);
  1303. if ($p && $p['title_id']) {
  1304. $t = explode(',', $p['title_id']);
  1305. if (in_array(2, $t)) {
  1306. $group = $p;
  1307. $group['title_name'] = '战略委';
  1308. $group['role_name'] = '';
  1309. if ($group['role']) {
  1310. $role = Dever::db('setting/role')->find($group['role']);
  1311. if ($role) {
  1312. $group['role_name'] = $role['name'];
  1313. }
  1314. }
  1315. break;
  1316. }
  1317. if (in_array(3, $t)) {
  1318. $group = $p;
  1319. $group['title_name'] = '决策委';
  1320. $group['role_name'] = '';
  1321. if ($group['role']) {
  1322. $role = Dever::db('setting/role')->find($group['role']);
  1323. if ($role) {
  1324. $group['role_name'] = $role['name'];
  1325. }
  1326. }
  1327. break;
  1328. }
  1329. if (in_array(9, $t)) {
  1330. $group = $p;
  1331. $group['title_name'] = '管理层';
  1332. $group['role_name'] = '';
  1333. if ($group['role']) {
  1334. $role = Dever::db('setting/role')->find($group['role']);
  1335. if ($role) {
  1336. $group['role_name'] = $role['name'];
  1337. }
  1338. }
  1339. break;
  1340. }
  1341. }
  1342. }
  1343. }
  1344. }
  1345. }
  1346. if (!$group) {
  1347. $group['name'] = $group['mobile'] = $group['idcard'] = $group['role_name'] = $group['title_name'] = '';
  1348. }
  1349. if($v){
  1350. $d = array
  1351. (
  1352. $v['name'],
  1353. $v['mobile'],
  1354. $v['idcard'],
  1355. $v['role_name'],
  1356. $v['title_name'],
  1357. $v['agent_cash'],
  1358. $parent['name'],
  1359. $parent['mobile'],
  1360. $parent['idcard'],
  1361. $parent['role_name'],
  1362. $parent['title_name'],
  1363. $group['name'],
  1364. $group['mobile'],
  1365. $group['idcard'],
  1366. $group['role_name'],
  1367. $group['title_name'],
  1368. $v['cdate'],
  1369. $udate,
  1370. $month,
  1371. );
  1372. $body[] = $d;
  1373. }
  1374. }
  1375. }
  1376. $file = Dever::input('excel_name');
  1377. return Dever::excelExport($body, $header, $file);
  1378. }
  1379. #新加期权业绩发放统计导出
  1380. public function out_member_cash($data)
  1381. {
  1382. $header = array('姓名','手机号','身份证号','角色','级别');
  1383. $year = date('Y',time());
  1384. if ($year == 2022) {
  1385. $m = 6;
  1386. $ym = 202206;
  1387. } elseif ($year >2022) {
  1388. $m = 1;
  1389. $ym = date('Ym',time());
  1390. }
  1391. for($i = $m; $i<=date('m',time()); $i++){
  1392. $month_config[]= $i.'月份业绩';
  1393. }
  1394. for ($i = $ym; $i<=date('Ym',time()); $i++) {
  1395. $month[] = $i.'01';
  1396. }
  1397. $header = array_merge($header,$month_config);
  1398. $body = array();
  1399. foreach ($data as $k => $v) {
  1400. $cash = Dever::db('bill/cash')->find(array('mid'=>$v['id']));
  1401. if ($cash) {
  1402. $role_name = '';
  1403. if (isset($v['role']) && $v['role']) {
  1404. $role = Dever::db('setting/role')->find($v['role']);
  1405. if ($role) {
  1406. $role_name = $role['name'];
  1407. }
  1408. }
  1409. $level_name = '';
  1410. if (isset($v['level_id']) && $v['level_id']) {
  1411. $level = Dever::db('setting/level')->find($v['level_id']);
  1412. if ($level) {
  1413. $level_name = $level['name'];
  1414. }
  1415. }
  1416. $d = array
  1417. (
  1418. $v['name'],
  1419. $v['mobile'],
  1420. $v['idcard'],
  1421. $role_name,
  1422. $level_name,
  1423. );
  1424. foreach ($month as $k1 => $v1) {
  1425. $w['mid'] = $v['id'];
  1426. $w['start'] = strtotime($v1);
  1427. $w['end'] = strtotime(date('Y-m-d',$w['start'])."+1 month - 1 day");
  1428. $w['type'] = '1,2';
  1429. $member_cash = Dever::db('bill/cash')->getMoney($w);
  1430. if ($member_cash && isset($member_cash['cash']) && $member_cash['cash']) {
  1431. $money = $member_cash['cash'];
  1432. } else {
  1433. $money = 0;
  1434. }
  1435. $d[] = $money;
  1436. }
  1437. $body[] = $d;;
  1438. }
  1439. }
  1440. $file = Dever::input('excel_name');
  1441. return Dever::excelExport($body, $header, $file);
  1442. }
  1443. public function out_order_touxian($data){
  1444. $header = array('姓名', '手机号', '身份证', '角色', '头衔', '代理费', '直推姓名', '直推手机号', '直推身份证', '直推角色', '直推头衔', '推荐人姓名', '推荐人手机号', '推荐人身份证', '推荐人角色', '推荐人头衔', '注册时间', '终审时间', '月份');
  1445. $body = array();
  1446. // print_R($data);die;
  1447. foreach($data as $k => $v) {
  1448. if ($v['parent_mid'] > 0) {
  1449. $v['role_name'] = '';
  1450. if ($v['role']) {
  1451. $role = Dever::db('setting/role')->find($v['role']);
  1452. if($role && $role['name']) {
  1453. $v['role_name'] = $role['name'];
  1454. }
  1455. }
  1456. $v['title_name'] = '';
  1457. $member = Dever::db('agent/member')->find($v['mid']);
  1458. if ($member && $member['title_id']) {
  1459. $title = Dever::db('setting/title')->getDataByIds(array('id' => $member['title_id']));
  1460. if($title) {
  1461. $v['title_name'] = array();
  1462. foreach ($title as $k1 => $v1) {
  1463. $v['title_name'][$v1['id']] = $v1['name'];
  1464. }
  1465. $v['title_name'] = implode('、', $v['title_name']);
  1466. }
  1467. }
  1468. // $v['agent_cash'] = 0;
  1469. // $order = Dever::db('agent/order')->getCount(array('mid'=>$v['id']));
  1470. // if ($order) {
  1471. // $v['agent_cash'] = $order['total'];
  1472. // }
  1473. $month = '';
  1474. $fdate = '';
  1475. #终审时间
  1476. if(isset($v['fdate']) && $v['fdate']) {
  1477. $month = date('m月',$v['fdate']);
  1478. $month = preg_replace('/^0+/', '', $month);
  1479. $fdate = date('Y-m-d H:i',$v['fdate']);
  1480. }
  1481. #注册时间
  1482. $v['cdate'] = date('Y-m-d H:i',$v['cdate']);
  1483. $parent = Dever::db('agent/member')->find($v['parent_mid']);
  1484. if (!$parent) {
  1485. continue;
  1486. }
  1487. $parent['role_name'] = '';
  1488. if ($parent && $parent['role']) {
  1489. $role = Dever::db('setting/role')->find($parent['role']);
  1490. if ($role) {
  1491. $parent['role_name'] = $role['name'];
  1492. }
  1493. }
  1494. $group = array();
  1495. $parent['title_name'] = '';
  1496. if ($parent['title_id']) {
  1497. $title = Dever::db('setting/title')->getDataByIds(array('id' => $parent['title_id']));
  1498. if ($title) {
  1499. $parent['title_name'] = array();
  1500. foreach ($title as $k1 => $v1) {
  1501. $parent['title_name'][$v1['id']] = $v1['name'];
  1502. if ($v1['id'] == 2 || $v1['id'] == 3 || $v1['id'] == 9) {
  1503. $group = $parent;
  1504. $group['title_name'] = $v1['name'];
  1505. }
  1506. }
  1507. $parent['title_name'] = implode('、', $parent['title_name']);
  1508. }
  1509. }
  1510. if (!$group) {
  1511. $top = Dever::load('invite/api')->getParentAll($v['mid'], 100);
  1512. if ($top) {
  1513. foreach ($top as $k1 => $v1) {
  1514. if ($v1['uid'] != $parent['id']) {
  1515. $p = Dever::db('agent/member')->one($v1['uid']);
  1516. if ($p && $p['title_id']) {
  1517. $t = explode(',', $p['title_id']);
  1518. if (in_array(2, $t)) {
  1519. $group = $p;
  1520. $group['title_name'] = '战略委';
  1521. $group['role_name'] = '';
  1522. if ($group['role']) {
  1523. $role = Dever::db('setting/role')->find($group['role']);
  1524. if ($role) {
  1525. $group['role_name'] = $role['name'];
  1526. }
  1527. }
  1528. break;
  1529. }
  1530. if (in_array(3, $t)) {
  1531. $group = $p;
  1532. $group['title_name'] = '决策委';
  1533. $group['role_name'] = '';
  1534. if ($group['role']) {
  1535. $role = Dever::db('setting/role')->find($group['role']);
  1536. if ($role) {
  1537. $group['role_name'] = $role['name'];
  1538. }
  1539. }
  1540. break;
  1541. }
  1542. if (in_array(9, $t)) {
  1543. $group = $p;
  1544. $group['title_name'] = '管理层';
  1545. $group['role_name'] = '';
  1546. if ($group['role']) {
  1547. $role = Dever::db('setting/role')->find($group['role']);
  1548. if ($role) {
  1549. $group['role_name'] = $role['name'];
  1550. }
  1551. }
  1552. break;
  1553. }
  1554. }
  1555. }
  1556. }
  1557. }
  1558. }
  1559. if (!$group) {
  1560. $group['name'] = $group['mobile'] = $group['idcard'] = $group['role_name'] = $group['title_name'] = '';
  1561. }
  1562. if($v){
  1563. $d = array
  1564. (
  1565. $v['name'],
  1566. $v['mobile'],
  1567. $v['idcard'],
  1568. $v['role_name'],
  1569. $v['title_name'],
  1570. $v['agent_cash'],
  1571. $parent['name'],
  1572. $parent['mobile'],
  1573. $parent['idcard'],
  1574. $parent['role_name'],
  1575. $parent['title_name'],
  1576. $group['name'],
  1577. $group['mobile'],
  1578. $group['idcard'],
  1579. $group['role_name'],
  1580. $group['title_name'],
  1581. $v['cdate'],
  1582. $fdate,
  1583. $month,
  1584. );
  1585. $body[] = $d;
  1586. }
  1587. }
  1588. }
  1589. $file = Dever::input('excel_name');
  1590. return Dever::excelExport($body, $header, $file);
  1591. }
  1592. }