Order.php 84 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994
  1. <?php
  2. namespace Agent\Lib;
  3. use Dever;
  4. class Order
  5. {
  6. /**
  7. * 下单
  8. *
  9. * @return mixed
  10. */
  11. public function action($mid)
  12. {
  13. Dever::config('base')->hook = true;
  14. $config = Dever::db('setting/base')->one();
  15. if($config['type'] == 2){
  16. Dever::alert($config['type_desc']);
  17. }
  18. $member = array();
  19. $parent_mid = -1;
  20. if ($mid > 0) {
  21. $member = Dever::db('agent/member')->find($mid);
  22. if (!$member) {
  23. Dever::alert('代理商不存在');
  24. }
  25. $mobile = $member['mobile'];
  26. $data['mid'] = $member['id'];
  27. $data['type'] = $member['type'];
  28. $data['name'] = $member['name'];
  29. $data['idcard'] = $member['idcard'];
  30. $data['idcard_front'] = $member['idcard_front'];
  31. $data['idcard_back'] = $member['idcard_back'];
  32. $data['company_name'] = $member['company_name'];
  33. $data['company_pic'] = $member['company_pic'];
  34. $data['company_number'] = $member['company_number'];
  35. $data['source_id'] = $member['source_id'];
  36. $code = Dever::input('code');
  37. if ($code) {
  38. $uid = Dever::load('invite/api')->getUid($code);
  39. if ($uid) {
  40. $user = Dever::db('agent/member')->find($uid);
  41. if ($user && $user['status'] <= 2) {
  42. $parent_mid = $user['id'];
  43. }
  44. $data['parent_code'] = $code;
  45. }
  46. } else {
  47. $parent_mid = $member['parent_mid'];
  48. if ($parent_mid && $parent_mid > 0) {
  49. $parent_code = Dever::load("invite/api.code", $parent_mid);
  50. if ($parent_code) {
  51. $data['parent_code'] = $parent_code;
  52. }
  53. }
  54. }
  55. } else {
  56. $mobile = Dever::input('mobile');
  57. $where['mobile'] = Dever::load('agent/lib/member')->checkMobile($mobile);
  58. $checkMember = Dever::db('agent/member')->find($where);
  59. if ($checkMember) {
  60. Dever::alert('注册失败,手机号已存在');
  61. }
  62. $code = Dever::input('code');
  63. if ($code) {
  64. $uid = Dever::load('invite/api')->getUid($code);
  65. if ($uid) {
  66. $user = Dever::db('agent/member')->find($uid);
  67. if ($user && $user['status'] <= 2) {
  68. $parent_mid = $user['id'];
  69. }
  70. $data['parent_code'] = $code;
  71. }
  72. }
  73. $data['type'] = Dever::input('type', 1);
  74. $data['name'] = Dever::input('name');
  75. $data['idcard'] = Dever::input('idcard');
  76. $data['idcard_front'] = Dever::input('idcard_front');
  77. $data['idcard_back'] = Dever::input('idcard_back');
  78. $data['company_name'] = Dever::input('company_name');
  79. $data['company_pic'] = Dever::input('company_pic');
  80. $data['company_number'] = Dever::input('company_number');
  81. $data['source_id'] = Dever::input('source_id');
  82. }
  83. if($data['idcard']){
  84. $birth = strlen($data['idcard'])==15 ? ('19' . substr($data['idcard'], 6, 6)) : substr($data['idcard'], 6, 8);
  85. $year=substr($birth,0,4);#出生年份
  86. $month=substr($birth,4,4);#出生日期
  87. $y=date('Y',time());#当前年份
  88. $m=date('md',time());#当前日期
  89. if(($m-$month)<0){
  90. $zhou=$y-$year-1;
  91. }else{
  92. $zhou=$y-$year;
  93. }
  94. if($zhou>=65 || $zhou<18){
  95. Dever::alert('您不满足申请条件,请联系客服');
  96. }
  97. }
  98. $idcard_path = Dever::input('idcard_path');
  99. if($idcard_path){
  100. $data['idcard_path'] = $idcard_path;
  101. $idcard_path = (array)json_decode($data['idcard_path']);
  102. if($idcard_path['face']){
  103. $rest = (array)$idcard_path['face'];
  104. if($data['name'] != $rest['name'] || $data['idcard'] != $rest['idNumber']){
  105. Dever::alert('姓名或身份证号不匹配');
  106. }
  107. }
  108. if($idcard_path['back']){
  109. $rest = (array)$idcard_path['back'];
  110. $date = explode('-',$rest['validPeriod']);
  111. if($date[1] && $date[1]!='长期'){
  112. $cdate = strtotime(str_replace('.','-',$date[1]));
  113. if(time()>=$cdate){
  114. Dever::alert('身份证背面已过期');
  115. }
  116. }
  117. }
  118. }
  119. if ($data['source_id'] && $data['source_id'] > 0) {
  120. $data['invite_type'] = 2;
  121. } else {
  122. $data['invite_type'] = 1;
  123. if ($parent_mid < 0) {
  124. Dever::alert('请填写正确的邀请码');
  125. }
  126. }
  127. Dever::load('agent/lib/member')->checkMcode($mobile);
  128. $data['mobile'] = $mobile;
  129. $data['parent_mid'] = $parent_mid;
  130. if (!$data['idcard_front']) {
  131. Dever::alert('身份证正面不能为空');
  132. }
  133. if (!$data['idcard_back']) {
  134. Dever::alert('身份证反面不能为空');
  135. }
  136. if ($data['type'] == 2) {
  137. if (!$data['company_name']) {
  138. Dever::alert('公司名称不能为空');
  139. }
  140. if (!$data['company_pic']) {
  141. Dever::alert('营业执照照片不能为空');
  142. }
  143. if (!$data['company_number']) {
  144. Dever::alert('营业执照号码不能为空');
  145. }
  146. }
  147. if (!$data['name']) {
  148. Dever::alert('姓名不能为空');
  149. }
  150. if (!$data['idcard']) {
  151. Dever::alert('身份证号不能为空');
  152. }
  153. if (!preg_match(Dever::rule('idcard'), $data['idcard'])) {
  154. Dever::alert('身份证号不正确');
  155. }
  156. $data += $this->getPrice($member);
  157. $data['sign'] = Dever::input('sign');
  158. /*
  159. if (!$data['sign']) {
  160. Dever::alert('手写签名不能为空');
  161. }*/
  162. $data['order_num'] = $this->getOrderId();
  163. # 付款信息
  164. $data['pay_type'] = Dever::input('pay_type', 1);
  165. if ($data['pay_type'] == 1 && $data['role']['type'] == 1) {
  166. //Dever::alert('暂时不支持在线支付');
  167. /*
  168. $data['openid'] = Dever::input('openid');
  169. if (!$data['openid']) {
  170. Dever::alert('请先授权');
  171. }
  172. */
  173. } elseif ($data['pay_type'] == 3) {
  174. $data['bank_id'] = Dever::input('bank_id');
  175. if (!$data['bank_id']) {
  176. Dever::alert('请选择银行');
  177. }
  178. $data['bank_card'] = Dever::input('bank_card');
  179. if (!$data['bank_card']) {
  180. Dever::alert('请输入银行卡号');
  181. }
  182. } else {
  183. # 汇款
  184. $data['pay_pic'] = Dever::input('pay_pic');
  185. if (!$data['pay_pic']) {
  186. Dever::alert('请上传打款凭证');
  187. }
  188. $data['pay_price'] = Dever::input('pay_price');
  189. }
  190. $where['mobile'] = $data['mobile'];
  191. $where['role'] = $data['role']['id'];
  192. $where['area'] = $data['area'];
  193. $info = Dever::db('agent/order')->find($where);
  194. if ($info && $info['status'] != 5) {
  195. //Dever::alert('请勿重复提交');
  196. }
  197. $data['role'] = $where['role'];
  198. $data['status'] = -2;
  199. $data['mid'] = Dever::load('agent/lib/member')->create($data);
  200. if ($data['mid']) {
  201. $data['udate'] = time();
  202. $data['id'] = Dever::db('agent/order')->insert($data);
  203. } else {
  204. $data['id'] = false;
  205. }
  206. if ($data['id']) {
  207. # 生成代理商
  208. $result = Dever::load('passport/reg')->getSign($data['mid']);
  209. $result['order_id'] = $data['id'];
  210. $result['msg'] = '您的申请已经提交完成,请耐心等待,我们将在工作日8小时内为您通过审核,非常感谢。';
  211. $agreement = Dever::db('setting/agreement')->getData();
  212. list($temp, $result['agreement_1']) = Dever::load('agent/lib/agreement')->name($agreement[1], $data, $data['role'], 1, 2);
  213. list($temp, $result['agreement_4']) = Dever::load('agent/lib/agreement')->name($agreement[4], $data, $data['role'], 1, 2);
  214. if ($data['pay_type'] == 3) {
  215. $result['bank_msg'] = '您需要使用银行卡:所有人('.$data['name'].'),账号('.$data['bank_card'].'),转账至如下账户('.$data['price_str'].'):';
  216. $config = Dever::db('setting/base')->find();
  217. $result['bank_user'] = $config['bank_user'];
  218. $result['bank_name'] = $config['bank_name'];
  219. $result['bank_card'] = $config['bank_card'];
  220. } elseif ($data['pay_type'] == 1) {
  221. # 在线支付 生成支付信息
  222. $result['pay'] = $this->pay($data);
  223. }
  224. return $result;
  225. } else {
  226. Dever::alert('登录失败');
  227. }
  228. }
  229. # 签名确认
  230. public function sign($mid, $order_id)
  231. {
  232. if (!$order_id) {
  233. Dever::alert('验证失败');
  234. }
  235. $where['mid'] = $mid;
  236. $where['id'] = $order_id;
  237. $info = Dever::db('agent/order')->find($where);
  238. if (!$info) {
  239. Dever::alert('验证失败');
  240. }
  241. if ($info['status'] != -2) {
  242. //Dever::alert('验证失败');
  243. }
  244. $update['sign'] = $sign = Dever::input('sign');
  245. if (!$update['sign']) {
  246. Dever::alert('请上传签名');
  247. }
  248. $update['status'] = 1;
  249. $update['where_id'] = $info['id'];
  250. $state = Dever::db('agent/order')->update($update);
  251. if ($state) {
  252. $update = array();
  253. $update['sign'] = $sign;
  254. $update['where_id'] = $mid;
  255. $state = Dever::db('agent/member')->update($update);
  256. $result = Dever::load('passport/reg')->getSign($mid);
  257. return $result;
  258. } else {
  259. Dever::alert('验证失败');
  260. }
  261. }
  262. /**
  263. * 发起在线支付
  264. *
  265. * @return mixed
  266. */
  267. public function pay($data)
  268. {
  269. $param = array
  270. (
  271. 'project_id' => 4,
  272. 'channel_id' => 1,
  273. 'system_source' => 1,
  274. 'account_id' => 8,
  275. 'uid' => $data['id'],
  276. 'name' => $data['name'],
  277. //'openid' => $data['openid'],
  278. 'cash' => $data['price'],
  279. 'product_id' => $data['id'],
  280. 'order_id' => $data['order_num'],
  281. 'h5' => 1,
  282. 'refer' => Dever::input('refer', 'http://guanli.uat.churenyiliao.com/data/payback/payback.html'),
  283. );
  284. $result = Dever::load('pay/api.pay', $param);
  285. $result['order_num'] = $data['order_num'];
  286. $result['order_id'] = $data['id'];
  287. return $result;
  288. }
  289. /**
  290. * 生成订单号
  291. *
  292. * @return mixed
  293. */
  294. public function getOrderId()
  295. {
  296. $where['order_num'] = Dever::order('D');
  297. $where['clear'] = true;
  298. $state = Dever::db('agent/order')->one($where);
  299. if (!$state) {
  300. return $where['order_num'];
  301. } else {
  302. return $this->getOrderId();
  303. }
  304. }
  305. # 支付成功回调 安全加密 设置token
  306. public function success_secure_api_token()
  307. {
  308. $project_id = Dever::input('pay_project_id');
  309. $info = Dever::db('pay/project')->one($project_id);
  310. if ($info) {
  311. return $info['key'];
  312. }
  313. return 'agent_buy_dever_2020';
  314. }
  315. # 支付成功回调 安全加密
  316. public function success_secure_api($param = array())
  317. {
  318. $this->success($param);
  319. }
  320. # 支付成功回调
  321. public function success($param = array())
  322. {
  323. $send = $param ? $param : Dever::preInput('pay_');
  324. $product_id = $send['pay_product_id'];
  325. $order_id = $send['pay_order_id'];
  326. $status = $send['pay_status'];
  327. $cash = $send['pay_cash'];
  328. $msg = $send['pay_msg'];
  329. $order = Dever::db('agent/order')->one(array('id' => $product_id, 'clear' => true));
  330. if ($order && $status == 2) {
  331. $update['pay_status'] = 2;
  332. $update['where_id'] = $order['id'];
  333. Dever::db('agent/order')->update($update);
  334. }
  335. return 'ok';
  336. }
  337. /**
  338. * 获取支付金额
  339. *
  340. * @return mixed
  341. */
  342. public function getPrice($member = false)
  343. {
  344. if ($member && !is_array($member)) {
  345. $member = Dever::db('agent/member')->find($member);
  346. }
  347. $data['role'] = Dever::input('role');
  348. if (!$data['role']) {
  349. Dever::alert('代理类型不能为空');
  350. }
  351. $data['role'] = Dever::db('setting/role')->find($data['role']);
  352. if (!$data['role']) {
  353. Dever::alert('代理类型不正确');
  354. }
  355. if ($data['role']['isbuy'] != 1) {
  356. Dever::alert('代理类型不正确');
  357. }
  358. $data['area'] = Dever::input('area');
  359. if ($data['role']['type'] == 2 && !$data['area']) {
  360. Dever::alert('代理区域不能为空');
  361. if (strstr($data['area'], '-1')) {
  362. Dever::alert('代理区域选择不正确');
  363. }
  364. }
  365. # 计算支付金额
  366. if ($data['role']['type'] == 1) {
  367. $data['price'] = $data['role']['price'];
  368. } elseif ($data['role']['type'] == 2) {
  369. $data['area'] = $this->checkArea($data['area'], $data['role'], $member ? $member['id'] : false);
  370. $data['price'] = Dever::load('area/api')->getPrice($data['role']['area'], $data['area']);
  371. if ($data['price'] <= 0) {
  372. Dever::alert('代理区域的代理价格为空,请联系客服');
  373. }
  374. } else {
  375. Dever::alert('代理类型不正确');
  376. }
  377. $data['order_type'] = 1;
  378. if ($member) {
  379. $member_role = Dever::db('setting/role')->find($member['role']);
  380. if ($member_role) {
  381. if ($member_role['levelup'] != 1) {
  382. Dever::alert('当前代理角色无法升级');
  383. } elseif ($member_role['levelup_yue'] == 1) {
  384. //$area = Dever::db('agent/member_area')->getOne(array('mid' => $member['id'], 'type' => 1));
  385. $price = Dever::db('agent/order')->getPrice(array('mid' => $member['id']));
  386. if ($price && $data['price'] > $price['total']) {
  387. $data['price'] -= $price['total'];
  388. } else {
  389. Dever::alert('该代理区域无法升级');
  390. }
  391. }
  392. $data['order_type'] = 2;
  393. }
  394. }
  395. if ($data['price'] >= 10000) {
  396. $data['price_str'] = ($data['price']/10000) . '万元';
  397. } else {
  398. $data['price_str'] = $data['price'] . '元';
  399. }
  400. if (is_int($data['price'])) {
  401. $data['price_str'] .= '整';
  402. }
  403. $data['f_price'] = $data['price'];
  404. return $data;
  405. }
  406. public function checkArea($area, $role, $mid = false)
  407. {
  408. if (is_string($area)) {
  409. $area = explode(',', $area);
  410. }
  411. $result = array();
  412. foreach ($area as $k => $v) {
  413. if ($role['area'] == 1) {
  414. if ($v < 0) {
  415. if ($k == 1) {
  416. Dever::alert('请选择城市');
  417. }
  418. } elseif ($k < 2) {
  419. $result[] = $v;
  420. }
  421. }
  422. if ($role['area'] == 2) {
  423. if ($v < 0) {
  424. if ($k == 1) {
  425. Dever::alert('请选择城市');
  426. } elseif ($k == 2) {
  427. Dever::alert('请选择区县');
  428. }
  429. } elseif ($k < 3) {
  430. $result[] = $v;
  431. }
  432. }
  433. if ($role['area'] == 3) {
  434. if ($v < 0) {
  435. if ($k == 1) {
  436. Dever::alert('请选择城市');
  437. } elseif ($k == 2) {
  438. Dever::alert('请选择区县');
  439. } elseif ($k == 3) {
  440. Dever::alert('请选择街道');
  441. }
  442. } elseif ($k < 4) {
  443. $result[] = $v;
  444. }
  445. }
  446. }
  447. $num = count($result);
  448. if ($role['area'] == 1 && $num < 2) {
  449. Dever::alert('请选择城市');
  450. } elseif ($role['area'] == 2 && $num < 3) {
  451. Dever::alert('请选择区县');
  452. } elseif ($role['area'] == 3 && $num < 4) {
  453. Dever::alert('请选择街道');
  454. }
  455. $result = implode(',', $result);
  456. $result = str_replace(',-1', '', $result);
  457. $area_info = Dever::db('agent/member_area')->getOne(array('area' => $result, 'role' => $role['id']));
  458. if ($area_info) {
  459. if ($mid && $mid > 0) {
  460. if ($mid != $area_info['mid']) {
  461. Dever::alert('该区域已被占用');
  462. }
  463. } else {
  464. Dever::alert('该区域已被占用');
  465. }
  466. }
  467. return $result;
  468. }
  469. # 展示订单详情
  470. public function show()
  471. {
  472. $id = Dever::input('order_id');
  473. $config = Dever::db('agent/order')->config['set'];
  474. $info = Dever::db('agent/order')->one($id);
  475. $admin = Dever::load('manage/auth.info');
  476. $admin_auth = false;
  477. if ($admin && $admin['role'] == 24){
  478. $admin_auth = $admin['role'];
  479. }
  480. $process = Dever::db('agent/order_process')->getData(array('order_id' => $id));
  481. $process_status = Dever::db('agent/order_process')->config['status'];
  482. //print_r($process);die;
  483. $role = Dever::db('setting/role')->one($info['role']);
  484. $area = Dever::load("area/api.string", $info['area'], '');
  485. $status = Dever::status($config['status'], $info['status']);
  486. $member = array();
  487. if ($info['mid'] > 0) {
  488. $member = Dever::db('agent/member')->one($info['mid']);
  489. }
  490. $parent_member = array();
  491. if ($info['parent_mid'] > 0) {
  492. $parent_member = Dever::db('agent/member')->one($info['parent_mid']);
  493. }
  494. $cdate = date('Y-m-d H:i', $info['cdate']);
  495. if ($info['fdate']) {
  496. $fdate = date('Y-m-d H:i', $info['fdate']);
  497. } else {
  498. $fdate = '';
  499. }
  500. $result = array();
  501. $result[$info['order_num']] = array
  502. (
  503. 'type' => 'user',
  504. 'content' => array
  505. (
  506. array('订单ID', $info['id']),
  507. array('订单状态', $status),
  508. array('订单类型', $config['order_type'][$info['order_type']]),
  509. array('申请日期', $cdate),
  510. array('管理员备注', $info['admin_desc']),
  511. )
  512. );
  513. if ($process) {
  514. foreach ($process as $k => $v) {
  515. $v['cdate'] = date('Y-m-d H:i', $v['cdate']);
  516. if($v['status'] == 1 || $v['status'] == 2){
  517. if (!$v['admin']) {
  518. $v['admin'] = 1;
  519. }
  520. $admin = Dever::load('manage/admin-find',$v['admin']);
  521. if($v['desc']){
  522. $v['cdate'] .= '<br/>操作人:'.$admin['username'].'<br/>备注:'.$v['desc'];
  523. }else{
  524. $v['cdate'] .= '<br/>操作人:'.$admin['username'];
  525. }
  526. }
  527. $result[$info['order_num']]['content'][] = array($process_status[$v['status']], $v['cdate']);
  528. }
  529. }
  530. $idcard_pic = '<a href="'.$info['idcard_front'].'" target="_blank"><img src="'.$info['idcard_front'].'" width="100" /></a>';
  531. if ($info['idcard_back']) {
  532. $idcard_pic .= '&nbsp;&nbsp;<a href="'.$info['idcard_back'].'" target="_blank"><img src="'.$info['idcard_back'].'" width="100" /></a>';
  533. }
  534. if ($info['sign']) {
  535. $sign_pic = '<a href="'.$info['sign'].'" target="_blank"><img src="'.$info['sign'].'" width="100" /></a>';
  536. } else {
  537. $sign_pic = '暂无';
  538. }
  539. $pay_pic = '';
  540. if ($info['pay_pic']) {
  541. $temp = explode(',', $info['pay_pic']);
  542. foreach ($temp as $k => $v) {
  543. $v = str_replace('https://cryl.yijiuguanfang.com/', 'http://d2.churenyiliao.com:8080/', $v);
  544. $pay_pic .= '&nbsp;&nbsp;<a href="'.$v.'" target="_blank"><img src="'.$v.'" width="100" /></a>';
  545. }
  546. }
  547. if (!$member['avatar']) {
  548. $default = Dever::db('passport/avatar')->one(1);
  549. $member['avatar'] = $default['avatar'];
  550. }
  551. $result['账号信息'] = array
  552. (
  553. 'type' => 'user',
  554. 'pic' => $member['avatar'],
  555. 'content' => array
  556. (
  557. array('类型', $config['type'][$info['type']]),
  558. array('姓名', $info['name']),
  559. array('手机号', $info['mobile']),
  560. array('代理角色', $role['name']),
  561. array('代理区域', $area),
  562. //array('注意', '赠送区域无权益'),
  563. array('身份证号码', $info['idcard']),
  564. ),
  565. );
  566. if ($info['type'] == 2) {
  567. $company_pic = '&nbsp;&nbsp;<a href="'.$info['company_pic'].'" target="_blank"><img src="'.$info['company_pic'].'" width="100" /></a>';
  568. $result['账号信息']['content'][] = array
  569. (
  570. array('企业名称', $info['company_name']),
  571. array('营业执照号码', $info['company_number']),
  572. array('营业执照照片', $company_pic),
  573. );
  574. }
  575. $result['账号信息']['content'][] = array('身份证照片', $idcard_pic);
  576. $result['账号信息']['content'][] = array('代理商签名', $sign_pic);
  577. if ($admin_auth) {
  578. $result['支付信息'] = array
  579. (
  580. 'type' => 'user',
  581. 'content' => array
  582. (
  583. array('支付方式', $config['pay_type'][$info['pay_type']]),
  584. array('支付状态', $config['pay_status'][$info['pay_status']]),
  585. array('付款备注', $info['desc']),
  586. array('应付金额', '¥' . $info['f_price'] . '元'),
  587. array('实付金额', '¥' . $info['price'] . '元'),
  588. // array('代理费', '¥' . $info['agent_cash'] . '元'),
  589. // array('软件服务费', '¥' . $info['soft_cash'] . '元'),
  590. // array('商品价值', '¥' . $info['goods_cash'] . '元'),
  591. // array('赠送期权价值', '¥' . $info['option_price'] . '元'),
  592. array('支付凭证', $pay_pic),
  593. ),
  594. );
  595. } else {
  596. $result['支付信息'] = array
  597. (
  598. 'type' => 'user',
  599. 'content' => array
  600. (
  601. array('支付方式', $config['pay_type'][$info['pay_type']]),
  602. array('支付状态', $config['pay_status'][$info['pay_status']]),
  603. array('付款备注', $info['desc']),
  604. array('应付金额', '¥' . $info['f_price'] . '元'),
  605. array('实付金额', '¥' . $info['price'] . '元'),
  606. array('代理费', '¥' . $info['agent_cash'] . '元'),
  607. array('软件服务费', '¥' . $info['soft_cash'] . '元'),
  608. array('商品价值', '¥' . $info['goods_cash'] . '元'),
  609. array('赠送期权价值', '¥' . $info['option_price'] . '元'),
  610. array('支付凭证', $pay_pic),
  611. ),
  612. );
  613. }
  614. if ($info['parent_mid'] && $info['parent_mid'] > 0) {
  615. $parent = Dever::db('agent/member')->one($info['parent_mid']);
  616. if ($parent) {
  617. $result['推荐人信息'] = Dever::load('agent/lib/member')->getShowInfo($parent,$admin_auth);
  618. }
  619. }
  620. $button = $this->show_button($process, $info, $role, $parent_member);
  621. if (($info['status'] == 3 || $info['status'] == 4) && $info['agent_cash'] >= 0) {
  622. if (isset($process[3]) && $process[3]) {
  623. $process[3]['type'] = explode(',', $process[3]['type']);
  624. }
  625. if ($info['import'] == 1) {
  626. # 分润信息
  627. if ($parent_member) {
  628. $this->show_parent($parent_member, $process, $info, $role, $result, $admin_auth);
  629. }
  630. # 权益信息
  631. $this->show_goods($process, $info, $role, $result);
  632. }
  633. # 合同信息
  634. $this->show_agreement($process, $info, $role, $sign_pic, $result);
  635. }
  636. $head = array
  637. (
  638. 'name' => '基本信息',
  639. 'btn' => $button,
  640. );
  641. $html = Dever::show($head, $result, false, false, 'dls-user-box');
  642. return $html;
  643. }
  644. private function show_button($process, $info, $role, $parent_member)
  645. {
  646. $button = array();
  647. $cstatus = ',cstatus,soft_price';
  648. $soft_price = 0;
  649. if ($role['soft'] && $info['price'] > 0 && $info['status'] > 1) {
  650. //$cstatus = ',cstatus';
  651. //$soft = '【<a href="" style="color:blue">拆分代理费</a>】';
  652. if (strstr($role['soft'], '%')) {
  653. $role['soft'] = str_replace('%', '', $role['soft']);
  654. $role['soft'] = $info['price'] * ($role['soft']/100);
  655. }
  656. $soft_price = $role['soft'];
  657. }
  658. $option_price = 0;
  659. if($role['option_price'] && $info['price'] > 0 && $info['status'] > 0){
  660. if(strstr($role['option_price'],'%')){
  661. $role['option_price'] = str_replace('%','',$role['option_price']);
  662. $role['option_price'] = $info['price'] * ($role['option_price']/100);
  663. }
  664. $option_price = $role['option_price'];
  665. }
  666. if (Dever::load('manage/auth')->checkFunc('agent.order', 'edit', '备注')) {
  667. $purl = Dever::url('project/database/update?project=agent&table=order&where_id='.$info['id'].'&col=admin_desc', 'manage');
  668. $button[] = array
  669. (
  670. 'type' => 'edit',
  671. 'link' => $purl,
  672. 'name' => '备注',
  673. );
  674. }
  675. if (Dever::load('manage/auth')->checkFunc('agent.order', 'edit1', '修改资料')) {
  676. if ($info['status'] <= 1 || $info['status'] == 5) {
  677. $purl = Dever::url('project/database/update?project=agent&table=order&where_id='.$info['id'].'&col=invite_type,parent_code,source_id,name,idcard,type,idcard_front,idcard_back,company_name,company_number,company_pic,pay_type,pay_pic,role,area', 'manage');
  678. $button[] = array
  679. (
  680. 'type' => 'edit',
  681. 'link' => $purl,
  682. 'name' => '修改资料',
  683. );
  684. }
  685. }
  686. if (Dever::load('manage/auth')->checkFunc('agent.order', 'edit_qiquan', '修改期权价值')) {
  687. $purl = Dever::url('project/database/update?project=agent&table=order&where_id='.$info['id'].'&col=option_price,soft_cash', 'manage');
  688. $button[] = array
  689. (
  690. 'type' => 'edit',
  691. 'link' => $purl,
  692. 'name' => '修改期权价值',
  693. );
  694. }
  695. if ($info['status'] <= 3 && $info['status'] > 0) {
  696. # 未完成审核的订单,可以随时挂起
  697. $button[] = array
  698. (
  699. 'type' => 'action',
  700. 'link' => Dever::url('lib/manage.setOrderStatus?id=' . $info['id'] . '&status=6&manage_log=update.agent.order', 'agent'),
  701. 'name' => '挂起',
  702. 'auth' => array('agent.order', 'edit2'),
  703. );
  704. } elseif ($info['status'] == 6) {
  705. # 恢复挂起
  706. $button[] = array
  707. (
  708. 'type' => 'action',
  709. 'link' => Dever::url('lib/manage.setOrderStatus?id=' . $info['id'] . '&status=' . $info['history_status'].'&manage_log=update.agent.order', 'agent'),
  710. 'name' => '恢复',
  711. 'auth' => array('agent.order', 'edit2'),
  712. );
  713. }
  714. if ($info['status'] <= 1 || $info['status'] == 5) {
  715. # 未完成审核的订单,可以随时取消
  716. $button[] = array
  717. (
  718. 'type' => 'action',
  719. 'link' => Dever::url('lib/manage.setOrderStatus?id=' . $info['id'] . '&status=7', 'agent'),
  720. 'name' => '取消订单',
  721. 'auth' => array('agent.order', 'close'),
  722. # 记录日志的表名,如果为空则使用auth里的agent.order
  723. //'log' => 'agent.order',
  724. );
  725. }
  726. if ($info['status'] == 1) {
  727. # 根据价值获取名额
  728. $prize = Dever::db('setting/prize')->find(array('type' => 1, 'price' => $info['price']));
  729. if ($prize) {
  730. $member_goods = Dever::db('agent/member_goods')->getOne(array('mid' => $info['mid'], 'type' => 3, 'type_id' => $prize['id']));
  731. if ($member_goods && $member_goods['num'] > 0) {
  732. # 有名额
  733. $cstatus = ',prize_type';
  734. }
  735. }
  736. $purl = Dever::url('project/database/update?project=agent&table=order_process&order_id='.$info['id'].'&status=1&col=order_id,status,audit,price,option_price,desc'.$cstatus.'&price='.$info['price'].'&soft_price=' . $soft_price.'&option_price='.$option_price, 'manage');
  737. if (isset($process[1]) && $process[1]) {
  738. $purl .= '&where_id=' . $process[1]['id'];
  739. }
  740. if (Dever::load('manage/auth')->checkFunc('agent.order', 'edit3', '业务初审')) {
  741. if ($parent_member) {
  742. if ($parent_member['status'] == 2) {
  743. $button[] = array
  744. (
  745. 'type' => 'edit',
  746. 'link' => $purl,
  747. 'name' => '业务初审',
  748. );
  749. } else {
  750. $button[] = array
  751. (
  752. 'type' => 'click',
  753. 'content' => 'showCs()',
  754. 'name' => '业务初审<script>function showCs(){layer.msg("直属上级未认证,无法进行初审")}</script>'
  755. );
  756. }
  757. } else {
  758. $button[] = array
  759. (
  760. 'type' => 'edit',
  761. 'link' => $purl,
  762. 'name' => '业务初审',
  763. );
  764. }
  765. }
  766. } elseif ($info['status'] == 2) {
  767. $purl = Dever::url('project/database/update?project=agent&table=order_process&order_id='.$info['id'].'&status=2&col=order_id,status,audit,desc', 'manage');
  768. if (isset($process[2]) && $process[2]) {
  769. $purl .= '&where_id=' . $process[2]['id'];
  770. }
  771. if (Dever::load('manage/auth')->checkFunc('agent.order', 'edit4', '财务终审')) {
  772. $button[] = array
  773. (
  774. 'type' => 'edit',
  775. 'link' => $purl,
  776. 'name' => '财务终审',
  777. );
  778. }
  779. } elseif ($info['status'] == 3) {
  780. $purl = Dever::url('project/database/update?project=agent&table=order_process&order_id='.$info['id'].'&status=3&col=order_id,status,type', 'manage');
  781. if (isset($process[3]) && $process[3]) {
  782. $purl .= '&where_id=' . $process[3]['id'];
  783. }
  784. if (Dever::load('manage/auth')->checkFunc('agent.order', 'edit5', '确认完成')) {
  785. $button[] = array
  786. (
  787. 'type' => 'edit',
  788. 'link' => $purl,
  789. 'name' => '确认完成',
  790. );
  791. }
  792. }
  793. #新加2022.4.8
  794. $button[] = array
  795. (
  796. 'type' => 'link',
  797. 'link' => 'refer',
  798. 'name' => '返回上一页',
  799. );
  800. return $button;
  801. }
  802. private function getAreaAgent($area, $value)
  803. {
  804. $city_role = Dever::db('setting/role')->find(array('type' => 2, 'area' => $value));
  805. if ($city_role) {
  806. $area_info = Dever::db('agent/member')->find(array('area' => $area, 'role' => $city_role['id']));
  807. if ($area_info && $area_info['status'] <= 2) {
  808. if ($area_info['level_id'] > 0) {
  809. $area_info['level'] = Dever::db('setting/level')->find($area_info['level_id']);
  810. } else {
  811. $area_info['level'] = array('id' => -1, 'name' => '普通', 'level' => 0, 'num' => 1, 'value' => '0');
  812. }
  813. $area_info['role'] = $city_role;
  814. return $area_info;
  815. }
  816. }
  817. return array();
  818. }
  819. private function show_parent($parent_member, $process, $info, $role, &$result, $admin_auth = false)
  820. {
  821. # 这里要获取上级信息
  822. $table = array();
  823. if ($admin_auth) {
  824. $table['head'] = array('类型', '姓名', '手机', '角色', '比例/数量', '金额/名称');
  825. } else {
  826. $table['head'] = array('类型', '姓名', '手机', '角色', '级别', '比例/数量', '金额/名称');
  827. }
  828. $table['body'] = array();
  829. $parents[0] = array('uid' => $parent_member['id'], 'level' => 0);
  830. $parents = array_merge($parents, Dever::load('invite/api')->getParentAll($parent_member['id'], 100));
  831. $parent_per = 0;
  832. $max_per = 15;
  833. $level_up = false;
  834. $html = '';
  835. $parent_name = '';
  836. # 获取区域代理
  837. $area_agent = array();
  838. if ($role['type'] == 2 && $role['area'] > 1) {
  839. if ($role['area'] == 2) {
  840. # 区县,只需获取城市代理
  841. $temp = explode(',', $info['area']);
  842. $area_agent['city'] = $this->getAreaAgent($temp[0] . ',' . $temp[1], 1);
  843. } elseif ($role['area'] == 3) {
  844. # 街道,同时获取区县和城市代理
  845. $temp = explode(',', $info['area']);
  846. $area_agent['city'] = $this->getAreaAgent($temp[0] . ',' . $temp[1], 1);
  847. $area_agent['county'] = $this->getAreaAgent($temp[0] . ',' . $temp[1] . ',' . $temp[2], 2);
  848. }
  849. }
  850. foreach ($parents as $k => $v) {
  851. $parent_info = Dever::db('agent/member')->find($v['uid']);
  852. if ($parent_info && $parent_info['status'] == 2) {
  853. $child_num = 0;
  854. $parent_role = Dever::db('setting/role')->find($parent_info['role']);
  855. if ($parent_info['level_id'] > 0) {
  856. $parent_level = Dever::db('setting/level')->find($parent_info['level_id']);
  857. } else {
  858. $parent_level = array('id' => -1, 'name' => '普通', 'level' => 0, 'num' => 1, 'value' => '0');
  859. }
  860. $cash = 0;
  861. $level = array();
  862. $param = array();
  863. # 自动升级
  864. $role_up = Dever::db('setting/role_up')->getData(array('role_id' => $parent_role['id']));
  865. if ($role_up) {
  866. if (!$parent_info['group_sell']) {
  867. $parent_info['group_sell'] = 0;
  868. }
  869. $group_sell = $parent_info['group_sell'] + $info['agent_cash'];
  870. if (!$child_num) {
  871. $child_num = Dever::load('invite/api')->getChildNum($v['uid'], 1);
  872. }
  873. foreach ($role_up as $rv) {
  874. if ($child_num >= $rv['num'] && $group_sell >= ($rv['sell']*10000)) {
  875. # 可以升级为新角色
  876. $rv_role = Dever::db('setting/role')->find($rv['t_role_id']);
  877. if ($rv_role) {
  878. $param['role_up'] = $rv;
  879. $parent_info['role'] = $rv_role['id'];
  880. $parent_role_name = $parent_role['name'] . '->' . $rv_role['name'];
  881. $parent_role = $rv_role;
  882. $parent_role['name'] = $parent_role_name;
  883. break;
  884. }
  885. }
  886. }
  887. }
  888. if ($parent_per < $max_per) {
  889. $order_cash = Dever::db('agent/order_cash')->getData(array('order_id' => $info['id'], 'parent_mid' => $v['uid'], 'type' => 2));
  890. if ($order_cash) {
  891. $cash = $order_cash['cash'];
  892. $parent_level['value'] = $order_cash['per'];
  893. $parent_per += $parent_level['value'];
  894. } else {
  895. # 根据团队业绩获取等级
  896. # 获取当前用户的团队业绩
  897. if (!$parent_info['group_sell']) {
  898. $parent_info['group_sell'] = 0;
  899. }
  900. $sell = $parent_info['group_sell'] + $info['agent_cash'];
  901. $level = Dever::db('setting/level')->getOne(array('target' => ($sell/10000)));
  902. if ($level && $level['level'] > $parent_level['level']) {
  903. # 升级
  904. $level_up = true;
  905. /* 本次升级不计算分润 注释这里即可 */
  906. $old = $parent_level;
  907. $parent_info['level_id'] = $level['id'];
  908. $parent_level = $level;
  909. $parent_level['name'] = $old['name'] . '->' . $level['name'];
  910. }
  911. # 获取直推人数
  912. $child_num = Dever::load('invite/api')->getChildNum($v['uid'], 1);
  913. if ($parent_level['id'] > 0 && $child_num >= $parent_level['num'] && $role['id'] != 7) {
  914. # 达到要求,开始团队分润
  915. if ($parent_per > 0) {
  916. $parent_level['value'] = $parent_level['value'] - $parent_per;
  917. }
  918. if ($parent_level['value'] > 0) {
  919. $cash += $info['agent_cash'] * ($parent_level['value']/100);
  920. $parent_per += $parent_level['value'];
  921. }
  922. }
  923. }
  924. # 直推佣金
  925. if ($k == 0) {
  926. $parent_name = $this->show_parent_reward($parent_info, $info, $role, $v, $parent_role, $parent_level, $child_num, $table, $admin_auth);
  927. $this->show_area_reward($parent_info, $info, $role, $v, $parent_role, $parent_level, $area_agent, $table);
  928. }
  929. }
  930. $param['type'] = 2;
  931. $param['order_id'] = $info['id'];
  932. $param['parent_mid'] = $parent_info['id'];
  933. if (isset($level_up) && $level_up && isset($level) && $level) {
  934. $param['parent_level'] = $level['id'];
  935. $param['child_num'] = $child_num;
  936. }
  937. if ($parent_level['id'] && $parent_level['value'] > 0 && $cash > 0) {
  938. $param['cash'] = $cash;
  939. $param['per'] = $parent_level['value'];
  940. $data_param = Dever::array_encode($param);
  941. $cash = '<a style="color:blue" class="set_cash" data-param="'.$data_param.'">' . $cash . '</a>';
  942. if (!$admin_auth) {
  943. $table['body'][] = array('团队佣金', $parent_info['name'], $parent_info['mobile'], $parent_role['name'], $parent_level['name'], $parent_level['value'] . '%', $cash);
  944. }
  945. } else {
  946. $param['cash'] = 0;
  947. $param['per'] = 0;
  948. $data_param = Dever::array_encode($param);
  949. $html .= '<a style="color:blue;display:none;" class="set_cash" data-param="'.$data_param.'">&nbsp;&nbsp;</a>';
  950. }
  951. }
  952. }
  953. if (!$table['body']) {
  954. $table['head'] = array();
  955. }
  956. if (isset($process[3]['type']) && is_array($process[3]['type']) && in_array(3, $process[3]['type'])) {
  957. $parent_title = '(已发放分润)';
  958. $parent_button = array();
  959. } else {
  960. $parent_title = '(未发放分润)' . $html;
  961. /*
  962. $parent_button[] = array
  963. (
  964. 'type' => 'link',
  965. 'link' => Dever::url('lib/order_set.home?order_id='.$info['id'].'&role_id=' . $info['role'], 'agent'),
  966. 'name' => '修改分润金额'
  967. );*/
  968. $furl = Dever::url('lib/manage.set_commit?json=1&type=3&order_id='.$info['id'], 'agent');
  969. $parent_button[] = array
  970. (
  971. 'type' => 'click',
  972. 'content' => 'setCash()',
  973. 'name' => '确认发放分润<script>function setCash(){layer.confirm(\'确定进行此项操作吗?\', function(){var cash = [];$(\'.set_cash\').each(function(){cash.push($(this).attr(\'data-param\'));});$.post(\''.$furl.'\',{param:cash.join(",")}, function(t){t=JSON.parse(t);showYes(t)})})}</script>'
  974. );
  975. }
  976. $parent_name = '';
  977. $result['分润信息' . $parent_title] = array
  978. (
  979. 'type' => 'table',
  980. 'content' => $table,
  981. 'head' => array('name' => '<span>' . $parent_name . '</span>', 'btn' => $parent_button),
  982. );
  983. }
  984. private function show_area_reward($parent_info, $info, $role, $v, $parent_role, $parent_level, $area_agent, &$table)
  985. {
  986. $order_cash = Dever::db('agent/order_cash')->getAll(array('order_id' => $info['id'], 'parent_mid' => $v['uid'], 'type' => 3));
  987. if ($order_cash) {
  988. foreach ($order_cash as $k => $v) {
  989. $v['cash'] = '<a style="color:blue">' . $v['cash'] . '</a>';
  990. $v['member'] = Dever::db('agent/member')->find($v['mid']);
  991. $v['level'] = Dever::db('setting/level')->find($v['member']['level_id']);
  992. $v['role'] = Dever::db('setting/role')->find($v['member']['role']);
  993. $table['body'][] = array('间推佣金', $v['member']['name'], $v['member']['mobile'], $v['role']['name'], $$v['level']['name'], $v['per'] . '%', $v['cash']);
  994. }
  995. } else {
  996. if (isset($area_agent['county']) && $area_agent['county'] && $area_agent['county']['id'] != $parent_info['id']) {
  997. $area_role_reward = Dever::db('setting/role_reward')->find(array('role_id' => $area_agent['county']['role']['id'], 't_role_id' => $role['id']));
  998. if ($area_role_reward) {
  999. if (strstr($area_role_reward['fzt_qn_value'], ',')) {
  1000. $temp = explode(',', $area_role_reward['fzt_qn_value']);
  1001. $area_role_reward['fzt_qn_value'] = $temp[1];
  1002. }
  1003. if ($area_role_reward['value_type'] == 1) {
  1004. $area_cash = round($info['agent_cash'] * ($area_role_reward['fzt_qn_value']/100), 2);
  1005. $area_per = $area_role_reward['fzt_qn_value'];
  1006. } else {
  1007. $area_cash = $area_role_reward['fzt_qn_value'];
  1008. $area_per = 0;
  1009. }
  1010. $area_param = array();
  1011. $area_param['type'] = 3;
  1012. $area_param['order_id'] = $info['id'];
  1013. $area_param['parent_mid'] = $area_agent['county']['id'];
  1014. $area_param['cash'] = $area_cash;
  1015. $area_param['per'] = $area_per;
  1016. $area_param = Dever::array_encode($area_param);
  1017. $area_cash = '<a style="color:blue" class="set_cash" data-param="'.$area_param.'">' . $area_cash . '</a>';
  1018. $table['body'][] = array('间推佣金', $area_agent['county']['name'], $area_agent['county']['mobile'], $area_agent['county']['role']['name'], $area_agent['county']['level']['name'], $area_per . '%', $area_cash);
  1019. }
  1020. }
  1021. if (isset($area_agent['city']) && $area_agent['city'] && $area_agent['city']['id'] != $parent_info['id']) {
  1022. $area_role_reward = Dever::db('setting/role_reward')->find(array('role_id' => $area_agent['city']['role']['id'], 't_role_id' => $role['id']));
  1023. if ($area_role_reward) {
  1024. if (strstr($area_role_reward['fzt_qn_value'], ',')) {
  1025. $temp = explode(',', $area_role_reward['fzt_qn_value']);
  1026. $area_role_reward['fzt_qn_value'] = $temp[0];
  1027. }
  1028. if ($area_role_reward['value_type'] == 1) {
  1029. $area_cash = round($info['agent_cash'] * ($area_role_reward['fzt_qn_value']/100), 2);
  1030. $area_per = $area_role_reward['fzt_qn_value'];
  1031. } else {
  1032. $area_cash = $area_role_reward['fzt_qn_value'];
  1033. $area_per = 0;
  1034. }
  1035. $area_param = array();
  1036. $area_param['type'] = 3;
  1037. $area_param['order_id'] = $info['id'];
  1038. $area_param['parent_mid'] = $area_agent['city']['id'];
  1039. $area_param['cash'] = $area_cash;
  1040. $area_param['per'] = $area_per;
  1041. $area_param = Dever::array_encode($area_param);
  1042. $area_cash = '<a style="color:blue" class="set_cash" data-param="'.$area_param.'">' . $area_cash . '</a>';
  1043. $table['body'][] = array('间推佣金', $area_agent['city']['name'], $area_agent['city']['mobile'], $area_agent['city']['role']['name'], $area_agent['city']['level']['name'], $area_per . '%', $area_cash);
  1044. }
  1045. }
  1046. }
  1047. }
  1048. private function show_parent_reward($parent_info, $info, $role, $v, $parent_role, $parent_level, $child_num, &$table, $admin_auth = false)
  1049. {
  1050. $parent_name = '邀请人:'.$parent_info['name'].','.$parent_info['mobile'].'&nbsp;&nbsp;邀请人角色:';
  1051. $order_cash = Dever::db('agent/order_cash')->getData(array('order_id' => $info['id'], 'parent_mid' => $v['uid'], 'type' => 1));
  1052. //$parent_name .= $parent_role['name'] . '('.$parent_level['name'].')';
  1053. # 根据角色获取佣金 直推
  1054. if (!$order_cash) {
  1055. $reward = Dever::db('setting/role_reward')->find(array('role_id' => $parent_info['role'], 't_role_id' => $info['role']));
  1056. if ($reward) {
  1057. $param = array();
  1058. $param['type'] = 1;
  1059. $param['order_id'] = $info['id'];
  1060. $param['parent_mid'] = $parent_info['id'];
  1061. $param['cash'] = 0;
  1062. $param['per'] = 0;
  1063. # 判断上级的等级,仅限区县和城市代理
  1064. if ($parent_role && $parent_role['type'] == 2 && $parent_role['area'] <= 2) {
  1065. if (strstr($parent_info['area'], '-1')) {
  1066. $parent_info['area'] = str_replace(',-1', '', $parent_info['area']);
  1067. }
  1068. if (strstr($info['area'], $parent_info['area'])) {
  1069. # 区域内
  1070. if ($reward['zt_qn_value'] && $reward['zt_qn_value'] > 0) {
  1071. $reward['value'] = $reward['zt_qn_value'];
  1072. }
  1073. } else {
  1074. # 区域外
  1075. if ($reward['zt_qw_value'] && $reward['zt_qw_value'] > 0) {
  1076. $reward['value'] = $reward['zt_qw_value'];
  1077. }
  1078. }
  1079. }
  1080. # 检测有没有名额,如果有,直接使用名额内的佣金比例和权益
  1081. if ($role['type'] == 1) {
  1082. $parent_goods = Dever::db('agent/member_goods')->getAll(array('mid' => $v['uid'], 'type' => 3));
  1083. if ($parent_goods) {
  1084. foreach ($parent_goods as $vg) {
  1085. if ($vg['num'] > 0) {
  1086. $parent_prize = Dever::db('setting/prize')->find($vg['type_id']);
  1087. if ($parent_prize && $parent_prize['type'] == 2 && $parent_prize['role'] == $role['id']) {
  1088. $reward['value'] = $parent_prize['per'];
  1089. $param['parent_goods_id'] = $vg['id'];
  1090. $param['prize_type'] = 2;
  1091. # 检测有没有名额权益
  1092. $prize_goods = Dever::db('setting/prize_goods')->select(array('prize_id' => $parent_prize['id']));
  1093. if ($prize_goods) {
  1094. foreach ($prize_goods as $pk => $pv) {
  1095. $param['goods'][] = $pv;
  1096. }
  1097. }
  1098. break;
  1099. }
  1100. }
  1101. }
  1102. }
  1103. }
  1104. $reward_state = false;
  1105. if ($reward['num'] == 1) {
  1106. # 每推荐1个,获取直推佣金
  1107. $reward_state = true;
  1108. } elseif ($reward['num'] > 1) {
  1109. # 每推荐多少个,获取直推佣金
  1110. /*
  1111. if (!$child_num) {
  1112. $child_num = Dever::load('invite/api')->getChildNum($v['uid'], 1);
  1113. }*/
  1114. $role_child_num = Dever::db('agent/member')->total(array('parent_mid' => $v['uid'], 'role' => $info['role'], 'status' => 2)) + 1;
  1115. //$child_num = Dever::db('agent/member')->getCountByRole(array('parent_mid' => $v['uid'], 'role' => $info['role'])) + 1;
  1116. if ($role_child_num >= $reward['num'] && $role_child_num % $reward['num'] == 0) {
  1117. $reward_state = true;
  1118. }
  1119. }
  1120. if ($reward_state) {
  1121. if ($reward['value_type'] == 1) {
  1122. $param['cash'] = round($info['agent_cash'] * ($reward['value']/100), 2);
  1123. $param['per'] = $reward['value'];
  1124. } else {
  1125. $param['cash'] = $reward['value'];
  1126. $param['per'] = 0;
  1127. }
  1128. }
  1129. # 额外赠送
  1130. $give = Dever::db('setting/role_reward_give')->getData(array('reward_id' => $reward['id']));
  1131. if ($give) {
  1132. if (!$child_num) {
  1133. $child_num = Dever::load('invite/api')->getChildNum($v['uid'], 1);
  1134. }
  1135. foreach ($give as $gv) {
  1136. if ($child_num == $gv['num']) {
  1137. $prize_goods = Dever::db('setting/prize_goods')->select(array('reward_give_id' => $gv['id']));
  1138. if ($prize_goods) {
  1139. foreach ($prize_goods as $pk => $pv) {
  1140. $param['goods'][] = $pv;
  1141. }
  1142. }
  1143. break;
  1144. }
  1145. }
  1146. }
  1147. /*
  1148. if ($reward['is_give'] == 1) {
  1149. $give = Dever::array_decode($reward['give']);
  1150. if (!$child_num) {
  1151. $child_num = Dever::load('invite/api')->getChildNum($v['uid'], 1);
  1152. }
  1153. foreach ($give as $gv) {
  1154. if (isset($gv['num']) && $child_num >= $gv['num'] && $child_num % $gv['num'] == 0) {
  1155. $prize_log = Dever::db('agent/member_prize')->find(array('mid' => $v['uid'], 'prize_id' => $gv['type'], 'child_num' => $child_num));
  1156. if (!$prize_log) {
  1157. $prize = Dever::db('setting/prize')->find($gv['type']);
  1158. $param['prize_id'] = $prize['id'];
  1159. $param['child_num'] = $child_num;
  1160. break;
  1161. }
  1162. }
  1163. }
  1164. }*/
  1165. # 自动升级
  1166. /*
  1167. $role_up = Dever::db('setting/role_up')->getData(array('role_id' => $parent_role['id']));
  1168. if ($role_up) {
  1169. if (!$parent_info['group_sell']) {
  1170. $parent_info['group_sell'] = 0;
  1171. }
  1172. $group_sell = $parent_info['group_sell'] + $info['agent_cash'];
  1173. if (!$child_num) {
  1174. $child_num = Dever::load('invite/api')->getChildNum($v['uid'], 1);
  1175. }
  1176. foreach ($role_up as $rv) {
  1177. if ($child_num >= $rv['num'] && $group_sell >= ($rv['sell']*10000)) {
  1178. # 可以升级为新角色
  1179. $rv_role = Dever::db('setting/role')->find($rv['t_role_id']);
  1180. if ($rv_role) {
  1181. $param['role_up'] = $rv;
  1182. $parent_role['name'] = $parent_role['name'] . '->' . $rv_role['name'];
  1183. break;
  1184. }
  1185. }
  1186. }
  1187. }*/
  1188. if ($param['cash'] >= 0) {
  1189. $data_param = Dever::array_encode($param);
  1190. $param['cash'] = '<a style="color:blue" class="set_cash" data-param="'.$data_param.'">' . $param['cash'] . '</a>';
  1191. } else {
  1192. unset($param['goods']);
  1193. }
  1194. if ($admin_auth) {
  1195. $table['body'][] = array('提成佣金', $parent_info['name'], $parent_info['mobile'], $parent_role['name'], $param['per'] . '%', $param['cash']);
  1196. } else {
  1197. $table['body'][] = array('直推佣金', $parent_info['name'], $parent_info['mobile'], $parent_role['name'], $parent_level['name'], $param['per'] . '%', $param['cash']);
  1198. }
  1199. }
  1200. } else {
  1201. $order_cash['cash'] = '<a style="color:blue">' . $order_cash['cash'] . '</a>';
  1202. if ($admin_auth) {
  1203. $table['body'][] = array('提成佣金', $parent_info['name'], $parent_info['mobile'], $parent_role['name'], $order_cash['per'] . '%', $order_cash['cash']);
  1204. } else {
  1205. $table['body'][] = array('直推佣金', $parent_info['name'], $parent_info['mobile'], $parent_role['name'], $parent_level['name'], $order_cash['per'] . '%', $order_cash['cash']);
  1206. }
  1207. if ($order_cash['prize_id'] && $order_cash['prize_id'] > 0) {
  1208. $prize = Dever::db('setting/prize')->find($order_cash['prize_id']);
  1209. }
  1210. if ($order_cash['goods'] && $order_cash['goods']) {
  1211. $param['goods'] = Dever::array_decode($order_cash['goods']);
  1212. }
  1213. }
  1214. /*
  1215. if (isset($prize) && $prize) {
  1216. $table['body'][] = array('赠送名额', $parent_info['name'], $parent_info['mobile'], $parent_role['name'], $parent_level['name'], '1', $prize['name']);
  1217. }
  1218. */
  1219. if (isset($param['goods'])) {
  1220. foreach ($param['goods'] as $pv) {
  1221. if ($pv['type'] == 1) {
  1222. $goods_info = Dever::load('goods/lib/info')->getInfoBySku($pv['type_id'], $pv['sku_id']);
  1223. if (isset($goods_info['sku'])) {
  1224. $sku = '-' . $goods_info['sku']['string'];
  1225. } else {
  1226. $sku = '';
  1227. }
  1228. $pv['name'] = '<a style="color:blue">' . $goods_info['name'] . $sku . '</a>';
  1229. } elseif ($pv['type'] == 2) {
  1230. $card = Dever::db('card/info')->find($pv['type_id']);
  1231. if ($card['create_type'] == 3) {
  1232. $pv['price'] = round($info['value']*($pv['num']/100), 2);
  1233. $pv['num'] = $pv['num'] . '%';
  1234. } else {
  1235. $pv['price'] = $card['value'] * $pv['num'];
  1236. }
  1237. $pv['name'] = '<a style="color:blue">' . $pv['price'] . '元' . $card['name'] . '</a>';
  1238. }
  1239. $table['body'][] = array('赠送权益', $parent_info['name'], $parent_info['mobile'], $parent_role['name'], $parent_level['name'], $pv['num'], $pv['name']);
  1240. }
  1241. }
  1242. return $parent_name;
  1243. }
  1244. private function show_goods($process, $info, $role, &$result)
  1245. {
  1246. $t = intval($info['agent_cash']/10000);
  1247. if ($t <= 0) {
  1248. $t = 1;
  1249. }
  1250. $s = $t;
  1251. $goods = Dever::db('agent/order_goods')->getData(array('order_id' => $info['id']));
  1252. if (!$goods) {
  1253. $goods = Dever::db('setting/role_goods')->getData(array('role_id' => $info['role'], 'give' => $info['order_type']));
  1254. } else {
  1255. $s = 1;
  1256. }
  1257. $process_button = array();
  1258. if (isset($process[3]['type']) && is_array($process[3]['type']) && in_array(2, $process[3]['type'])) {
  1259. $process_status = 1;
  1260. $process_title = '(已发放权益)';
  1261. } else {
  1262. $process_status = 2;
  1263. $process_title = '(未发放权益)';
  1264. $process_button[] = array(
  1265. 'type' => 'link',
  1266. 'link' => Dever::url('lib/order_set.home?type='.$info['order_type'].'&order_id='.$info['id'].'&role_id=' . $info['role'] . '&total=' . $t, 'agent'),
  1267. 'name' => '修改权益',
  1268. 'auth' => array('agent.order', 'edit6'),
  1269. );
  1270. $process_button[] = array(
  1271. 'type' => 'action',
  1272. 'link' => Dever::url('lib/manage.set_commit?json=1&type=2&order_id='.$info['id'], 'agent'),
  1273. 'name' => '确认发放权益',
  1274. 'auth' => array('agent.order', 'edit7'),
  1275. );
  1276. }
  1277. if ($goods) {
  1278. $table = array();
  1279. $table['head'] = array('权益类型', '权益名称', '权益价值', '数量/百分比');
  1280. $table['body'] = array();
  1281. foreach ($goods as $k => $v) {
  1282. if ($v['type'] == 1) {
  1283. $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v['type_id'], $v['sku_id']);
  1284. if (isset($goods_info['sku'])) {
  1285. $sku = '-' . $goods_info['sku']['string'];
  1286. } else {
  1287. $sku = '';
  1288. }
  1289. $v['num'] = $v['num'] * $t;
  1290. $table['body'][] = array('商品', $goods_info['name'] . $sku, $goods_info['price'], $v['num']);
  1291. } elseif ($v['type'] == 2) {
  1292. $t = $s;
  1293. $card = Dever::db('card/info')->find($v['type_id']);
  1294. if ($card) {
  1295. if ($card['create_type'] == 3) {
  1296. $card['value'] = round($info['agent_cash']*($v['num']/100), 2);
  1297. $v['num'] = $v['num'] . '%';
  1298. } else {
  1299. $v['num'] = $v['num'] * $t;
  1300. $card['value'] = $card['value'] * $v['num'];
  1301. }
  1302. $table['body'][] = array('电子券', $card['name'], $card['value'], $v['num']);
  1303. }
  1304. } elseif ($v['type'] == 3) {
  1305. $prize = Dever::db('setting/prize')->find($v['type_id']);
  1306. $v['num'] = $v['num'] * $t;
  1307. if ($role['max_me_num'] && $role['max_me_num'] < $v['num']) {
  1308. $v['num'] = $role['max_me_num'];
  1309. }
  1310. $table['body'][] = array('名额', $prize['name'], $prize['price'], $v['num']);
  1311. }
  1312. }
  1313. $result['权益信息' . $process_title] = array
  1314. (
  1315. 'type' => 'table',
  1316. 'head' => array('name' => '权益列表:', 'btn' => $process_button),
  1317. 'content' => $table,
  1318. );
  1319. }
  1320. }
  1321. # 合同
  1322. private function show_agreement($process, $info, $role, $sign_pic, &$result)
  1323. {
  1324. $table = array();
  1325. $table['head'] = array('合同类型', '合同名称', '合同签名', '合同状态');
  1326. $table['body'] = array();
  1327. $agreement_type = Dever::db('setting/agreement')->config['config_type'];
  1328. $agreement_status = Dever::db('agent/member_agreement')->config['status'];
  1329. $agreement_button = array();
  1330. if ((isset($process[3]['type']) && is_array($process[3]['type']) && in_array(5, $process[3]['type'])) || $info['import'] > 1) {
  1331. $agreement_title = '(已生成合同)';
  1332. $agreement = Dever::db('agent/member_agreement')->getData(array('order_id' => $info['id']));
  1333. if ($agreement) {
  1334. foreach ($agreement as $k => $v) {
  1335. $agreement_info = Dever::db('setting/agreement')->find($v['agreement_id']);
  1336. $agreement_status_name = Dever::status($agreement_status, $v['status']);
  1337. $table['body'][] = array(Dever::status($agreement_type, $agreement_info['type']), Dever::load('agent/lib/agreement')->name($agreement_info, $v, $role, 2), $sign_pic, $agreement_status_name);
  1338. }
  1339. } else {
  1340. $agreement_title = '';
  1341. }
  1342. } else {
  1343. $agreement_title = '(未生成合同)';
  1344. $agreement_button[] = array(
  1345. 'type' => 'action',
  1346. 'link' => Dever::url('lib/manage.set_commit?json=1&type=5&order_id='.$info['id'], 'agent'),
  1347. 'name' => '生成代理合同',
  1348. 'auth' => array('agent.order', 'edit8'),
  1349. );
  1350. $agreement = Dever::db('setting/agreement')->getData();
  1351. $agreement_status_name = Dever::status($agreement_status, 1);
  1352. $table['body'][] = array(Dever::status($agreement_type, $agreement[1]['type']), Dever::load('agent/lib/agreement')->name($agreement[1], $info, $role, 1), $sign_pic, $agreement_status_name);
  1353. if ($info['soft_cash'] && $info['soft_cash'] > 0) {
  1354. $table['body'][] = array($agreement_type[$agreement[3]['type']], Dever::load('agent/lib/agreement')->name($agreement[3], $info, $role, 1), $sign_pic, $agreement_status_name);
  1355. }
  1356. if ($info['order_type'] == 2) {
  1357. # 升级的话,增加解除合同
  1358. $table['body'][] = array(Dever::status($agreement_type, $agreement[2]['type']), Dever::load('agent/lib/agreement')->name($agreement[2], $info, $role, 1), $sign_pic, $agreement_status_name);
  1359. } else {
  1360. $table['body'][] = array(Dever::status($agreement_type, $agreement[4]['type']), Dever::load('agent/lib/agreement')->name($agreement[4], $info, $role, 1), $sign_pic, $agreement_status_name);
  1361. }
  1362. }
  1363. $result['代理合同' . $agreement_title] = array
  1364. (
  1365. 'type' => 'table',
  1366. 'head' => array('name' => '&nbsp;', 'btn' => $agreement_button),
  1367. 'content' => $table
  1368. );
  1369. }
  1370. public function set_cdate($id){
  1371. $info=Dever::db('agent/order')->one(array('id'=>$id,'state'=>1));
  1372. if($info['cdate']){
  1373. $data['注册']=date('Y-m-d H:i',$info['cdate']);
  1374. }else{
  1375. $data['注册']='-';
  1376. }
  1377. $order_process=Dever::db('agent/order_process')->one(array('status'=>1,'order_id'=>$info['id'],'state'=>1));
  1378. if($order_process && $order_process['cdate']){
  1379. $data['初审']=date('Y-m-d H:i',$order_process['cdate']);
  1380. }else{
  1381. $data['初审']='-';
  1382. }
  1383. $order_process=Dever::db('agent/order_process')->one(array('status'=>2,'order_id'=>$info['id'],'state'=>1));
  1384. if($order_process && $order_process['cdate']){
  1385. $data['终审']=date('Y-m-d H:i',$order_process['cdate']);
  1386. }else{
  1387. $data['终审']='-';
  1388. }
  1389. if($info['fdate']){
  1390. $data['完成']=date('Y-m-d H:i',$info['fdate']);
  1391. }else{
  1392. $data['完成']='-';
  1393. }
  1394. $html = $data['注册'];
  1395. $html .= '<br />' . $data['初审'];
  1396. $html .= '<br />' . $data['终审'];
  1397. $html .= '<br />' . $data['完成'];
  1398. return $html;
  1399. // '注册时间:'.$zhuce.'<br/>初审时间:'.$chushen.'<br/>终审时间:'.$zhongshen.'<br/>完成时间:'.$wancheng;
  1400. }
  1401. public function set_price($id){
  1402. $info=Dever::db('agent/order')->one(array('id'=>$id,'state'=>1));
  1403. $html = $info['f_price'];
  1404. $html .= '<br />' . $info['price'];
  1405. $html .= '<br />' . $info['agent_cash'];
  1406. $html .= '<br />' . $info['soft_cash'];
  1407. return $html;
  1408. $data['注册金额']=$info['f_price'];
  1409. $data['实付金额']=$info['price'];
  1410. $data['代理费']=$info['agent_cash'];
  1411. $data['软件服务费']=$info['soft_cash'];
  1412. $html=Dever::table($data);
  1413. return $html;
  1414. }
  1415. public function new_set($id){
  1416. $info = Dever::db('agent/order')->find($id);
  1417. $name = Dever::load("agent/lib/member.getOne", $id, "agent/order");
  1418. $area = Dever::load("area/api.string", $info['area']);
  1419. $html = $name.'<br/>'.$area;
  1420. return $html;
  1421. }
  1422. #订单导出
  1423. public function out_order($data){
  1424. $header = array('邀请码', '姓名', '手机号', '身份证号', '会员角色', '代理商区域', '注册金额', '代理费', '直推业绩', '团队业绩', '申请类型','公司名称','申请时间', '初审时间','初审人','终审时间','终审人','审核状态','分润发放时间','分润发放人','权益发放时间','权益发放人','管理员备注','推荐人姓名','推荐人电话','推荐人等级','推荐人代理地区');
  1425. $body = array();
  1426. foreach($data as $k => $v){
  1427. $config = Dever::db('agent/order')->config['set'];
  1428. $status = Dever::status($config['status'], $v['status']);
  1429. $member = Dever::db('agent/member')->find(array('id'=>$v['mid']));
  1430. $code = Dever::load("invite/api.code", $member['id']);
  1431. if($member['type'] == 1){
  1432. $member_type = '个人';
  1433. }else{
  1434. $member_type = '公司';
  1435. }
  1436. $role = Dever::db('setting/role')->find(array('id'=>$v['role']));
  1437. $area = Dever::load("area/api.string", $v['area']);
  1438. $parent = Dever::db('agent/member')->find(array('id'=>$v['parent_mid']));
  1439. $parent_rolename = '';
  1440. $parent_name = '';
  1441. $parent_mobile = '';
  1442. $parent_area = '';
  1443. if($parent){
  1444. if($parent['role']){
  1445. $parent_role = Dever::db('setting/role')->find(array('id'=>$parent['role']));
  1446. if($parent_role){
  1447. $parent_rolename = $parent_role['name'];
  1448. }
  1449. }
  1450. if($parent['area']){
  1451. $parent_area = Dever::load("area/api.string", $parent['area']);
  1452. }
  1453. if($parent['name']){
  1454. $parent_name = $parent['name'];
  1455. }
  1456. if($parent['mobile']){
  1457. $parent_mobile = $parent['mobile'];
  1458. }
  1459. }
  1460. $process = Dever::db('agent/order_process')->state(array('order_id'=>$v['id']));
  1461. $chu = '';
  1462. $zhong = '';
  1463. $qy = '';
  1464. $fr = '';
  1465. $bh = '';
  1466. $chushen = '';
  1467. $zhongshen = '';
  1468. $audit_cdate = '';
  1469. $member_goods_log = Dever::db('agent/member_goods_log')->find(array('parent_order_num'=>$v['order_num']));
  1470. if($member_goods_log){
  1471. $quanyi = Dever::load('manage/api')->getLog($member_goods_log['id'], 'agent', 'member_goods_log', 1);
  1472. if($quanyi){
  1473. $admin = Dever::load('manage/admin-find',$quanyi['admin']);
  1474. if($admin){
  1475. $qy = $admin['username'];
  1476. }
  1477. }
  1478. }
  1479. $qydate = '';
  1480. $member_goods = Dever::db('agent/member_goods')->getQone(array('mid'=>$v['mid'],'state'=>1));
  1481. if($member_goods && $member_goods['cdate']){
  1482. $qydate = date('Y-m-d H:i',$member_goods['cdate']);
  1483. }
  1484. $order_cash = Dever::db('agent/order_cash')->find(array('order_id'=>$v['id']));
  1485. if($order_cash && $order_cash['id']){
  1486. $fenrun = Dever::load('manage/api')->getLog($order_cash['id'], 'agent', 'order_cash', 1);
  1487. if($fenrun && $fenrun['admin']){
  1488. $admin = Dever::load('manage/admin-find',$fenrun['admin']);
  1489. if($admin){
  1490. $fr = $admin['username'];
  1491. }
  1492. }
  1493. }
  1494. $frdate = '';
  1495. if($order_cash && $order_cash['cdate']){
  1496. $frdate = date('Y-m-d H:i',$order_cash['cdate']);
  1497. }
  1498. if($process){
  1499. foreach($process as $key => $val){
  1500. $log = Dever::load('manage/api')->getLog($val['id'], 'agent', 'order_process', 1);
  1501. if($val['status'] == 1){
  1502. if($val && $val['admin']){
  1503. $admin = Dever::load('manage/admin-find',$val['admin']);
  1504. $chu = $admin['username'];
  1505. }elseif($log && $log['admin']){
  1506. $admin = Dever::load('manage/admin-find',$log['admin']);
  1507. $chu = $admin['username'];
  1508. }
  1509. $chushen = date('Y-m-d H:i',$val['cdate']);
  1510. }elseif($val['status'] == 2){
  1511. $zhongshen = date('Y-m-d H:i',$val['cdate']);
  1512. if($val && $val['admin']){
  1513. $admin = Dever::load('manage/admin-find',$val['admin']);
  1514. $zhong = $admin['username'];
  1515. }elseif($log && $log['admin']){
  1516. $admin = Dever::load('manage/admin-find',$log['admin']);
  1517. $zhong = $admin['username'];
  1518. }
  1519. }
  1520. }
  1521. }
  1522. $d = array
  1523. (
  1524. $code,
  1525. $member['name'],
  1526. $member['mobile'],
  1527. $member['idcard'],
  1528. $role['name'],
  1529. $area,
  1530. $v['f_price'],
  1531. $v['agent_cash'],
  1532. $member['sell'],
  1533. $member['group_sell'],
  1534. $member_type,
  1535. $v['company_name'],
  1536. date('Y-m-d H:i',$v['cdate']),
  1537. $chushen,
  1538. $chu,
  1539. $zhongshen,
  1540. $zhong,
  1541. $status,
  1542. $frdate,
  1543. $fr,
  1544. $qydate,
  1545. $qy,
  1546. $v['admin_desc'],
  1547. $parent_name,
  1548. $parent_mobile,
  1549. $parent_rolename,
  1550. $parent_area,
  1551. );
  1552. $body[] = $d;
  1553. }
  1554. $file = Dever::input('excel_name');;
  1555. return Dever::excelExport($body, $header, $file);
  1556. }
  1557. public function getArea($id){
  1558. $info = Dever::db('agent/order')->find($id);
  1559. if($info['area']){
  1560. $area = Dever::load("area/api.string", $info['area']);
  1561. }else{
  1562. $area = '';
  1563. }
  1564. return $area;
  1565. }
  1566. #软件服务费导出
  1567. public function out_softorder($data){
  1568. $header = array('合同乙方', '手机号码', '身份证号码', '合同总期数(年)', '合同类型', '签订日期', '合同金额', '购买日期', '录入日期', '终审日期');
  1569. $body = array();
  1570. foreach($data as $k => $v){
  1571. if($v['soft_cash'] && $v['soft_cash']>0){
  1572. $role = Dever::db('setting/role')->find($v['role']);
  1573. $type = 2;
  1574. # 这里加判断
  1575. if ($role['type'] == 2 && $role['area'] == 1) {
  1576. $type = 1;
  1577. } elseif ($v['soft_cash'] > 6000 && $v['soft_cash'] <= 30000 && $v['soft_cash']%5000 == 0) {
  1578. $type = 3;
  1579. } elseif ($v['soft_cash'] <= 6000 && $v['soft_cash']%1000 == 0) {
  1580. $type = 4;
  1581. } else {
  1582. $type = 2;
  1583. }
  1584. # 城市代理
  1585. if ($type == 1) {
  1586. $name = '城市代理版';
  1587. $year = 1;
  1588. }
  1589. # 定制版
  1590. elseif ($type == 2) {
  1591. $name = '定制版';
  1592. $year = 1;
  1593. }
  1594. # 升级版
  1595. elseif ($type == 3) {
  1596. $name = '升级版';
  1597. $year = intval($v['soft_cash']/5000);
  1598. if ($year > 6) {
  1599. $year = 6;
  1600. }
  1601. }
  1602. # 基础版
  1603. else {
  1604. $name = '基础版';
  1605. $year = intval($v['soft_cash']/1000);
  1606. if ($year > 6) {
  1607. $year = 6;
  1608. }
  1609. }
  1610. if($v['cdate']){
  1611. $cdate = date('Y-m-d H:i',$v['cdate']);
  1612. }else{
  1613. $cdate = '-';
  1614. }
  1615. $order_process = Dever::db('agent/order_process')->one(array('status'=>1,'order_id'=>$v['id'],'state'=>1));
  1616. if($order_process && $order_process['cdate']){
  1617. $chu_cdate = date('Y-m-d H:i',$order_process['cdate']);
  1618. }else{
  1619. $chu_cdate = '-';
  1620. }
  1621. $order_process = Dever::db('agent/order_process')->one(array('status'=>2,'order_id'=>$v['id'],'state'=>1));
  1622. if($order_process && $order_process['cdate']){
  1623. $zcdate = date('Y-m-d H:i',$order_process['cdate']);
  1624. }else{
  1625. $zcdate = '-';
  1626. }
  1627. $d = array
  1628. (
  1629. $v['name'],
  1630. $v['mobile'],
  1631. $v['idcard'],
  1632. $year,
  1633. $name,
  1634. $zcdate,
  1635. $v['soft_cash'],
  1636. $cdate,
  1637. $cdate,
  1638. $zcdate,
  1639. );
  1640. $body[] = $d;
  1641. }
  1642. }
  1643. $file = Dever::input('excel_name');
  1644. return Dever::excelExport($body, $header, $file);
  1645. }
  1646. public function out_beidiaoorder($data){
  1647. $db = Dever::db('agent/test:old');
  1648. $header = array('姓名', '手机号', '身份证号', '注册日期', '角色', '代理金额', '直推奖励合计');
  1649. $month_config = array('2021-08', '2021-09', '2021-10', '2021-11','2021-12', '2022-01', '2022-02', '2022-03', '2022-04','2022-05','2022-06');
  1650. $header = array_merge($header, $month_config);
  1651. $body = array();
  1652. foreach($data as $k => $v){
  1653. $cdate = '';
  1654. if($v['cdate']){
  1655. $cdate = date('Y-m-d H:i',$v['cdate']);
  1656. }
  1657. $role_name = '';
  1658. if($v['role']){
  1659. $role = Dever::db('setting/role')->find($v['role']);
  1660. if($role && $role['name']){
  1661. $role_name = $role['name'];
  1662. }
  1663. }
  1664. $cash = 0;
  1665. $month_cash = array();
  1666. $month = array();
  1667. $bill = Dever::db('bill/cash')->select(array('mid' => $v['mid'], 'type' => 1));
  1668. if ($bill) {
  1669. foreach ($bill as $k1 => $v1) {
  1670. $time = date('Y-m', $v1['cdate']);
  1671. if (!isset($month[$time])) {
  1672. $month[$time] = 0;
  1673. }
  1674. $month[$time] += $v1['cash'];
  1675. $cash += $v1['cash'];
  1676. }
  1677. }
  1678. if ($v['mid'] < 50000) {
  1679. $member = $db->fetch('select * from ims_ewei_shop_member where id = ' . $v['mid'] . '');
  1680. if ($member) {
  1681. if ($member['uid'] && $member['uid'] > 0) {
  1682. $record = $db->fetchAll('select * from `ims_ewei_shop_member_credit_record` where uid = '.$member['uid'].' and `remark` LIKE "%推荐%" and credittype = "credit2"');
  1683. } elseif ($member['openid']) {
  1684. $record = $db->fetchAll('select * from `ims_ewei_shop_member_credit_record` where `remark` LIKE "%推荐%" and `remark` LIKE "%'.$member['openid'].'%" and credittype = "credit2"');
  1685. }
  1686. if (isset($record) && $record) {
  1687. foreach ($record as $k1 => $v1) {
  1688. $time = date('Y-m', $v1['createtime']);
  1689. if (!isset($month[$time])) {
  1690. $month[$time] = 0;
  1691. }
  1692. $month[$time] += $v1['num'];
  1693. $cash += $v1['num'];
  1694. }
  1695. }
  1696. }
  1697. }
  1698. if (!$cash) {
  1699. $cash = 0;
  1700. }
  1701. $d = array
  1702. (
  1703. $v['name'],
  1704. $v['mobile'],
  1705. $v['idcard'],
  1706. $cdate,
  1707. $role_name,
  1708. $v['agent_cash'],
  1709. $cash,
  1710. );
  1711. foreach ($month_config as $k2 => $v2) {
  1712. if (isset($month[$v2]) && $month[$v2]) {
  1713. $d[] = $month[$v2];
  1714. } else {
  1715. $d[] = 0;
  1716. }
  1717. }
  1718. $body[] = $d;
  1719. }
  1720. $file = Dever::input('excel_name');
  1721. $test = Dever::input('test');
  1722. if ($test == 1) {
  1723. print_r($body);die;
  1724. }
  1725. return Dever::excelExport($body, $header, $file);
  1726. }
  1727. # 修改区域
  1728. public function editArea($member, $area)
  1729. {
  1730. $order = Dever::db('agent/order')->find(array('mid' => $member['id'], 'role' => $member['role']));
  1731. if ($order && $order['area'] != $area) {
  1732. Dever::db('agent/order')->update(array('where_id' => $order['id'], 'area' => $area));
  1733. }
  1734. }
  1735. public function out_guidian($data){
  1736. $header = array('代理商名称', '电话', '角色', '审核完成时间','上级代理商姓名','上级代理商电话', '归店业绩', '门店名称', '门店编号', '创V名额外业绩', '归店时间');
  1737. $body = array();
  1738. foreach($data as $k => $v){
  1739. $member_shop = Dever::db('agent/member_shop_log')->find(array('mid'=>$v['parent_mid']));
  1740. if ($member_shop) {
  1741. if ($v['fdate'] > $member_shop['cdate'] || ($v['fdate'] < $member_shop['cdate'] && date('Ym',$v['fdate']) == date('Ym',$member_shop['cdate']))) {
  1742. $member = Dever::db('agent/member')->find($v['mid']);
  1743. $parent_member = Dever::db('agent/member')->find(array('id'=>$v['parent_mid']));
  1744. $role = Dever::db('setting/role')->find($member['role']);
  1745. $shop = Dever::db('shop/info')->find($member_shop['new_shop_id']);
  1746. $shop_stat = '';
  1747. $g_price = '';#归店业绩
  1748. if ($v['role'] != 8) {
  1749. // $g_price = $v['price'];#归店业绩
  1750. $g_price = $v['agent_cash'];
  1751. }
  1752. if ($member['prize_type'] == 1 && $member['role'] == 8) {
  1753. // $shop_stat = $v['price'];
  1754. $shop_stat = $v['agent_cash'];
  1755. }
  1756. $fdate = '';
  1757. if ($v['fdate']) {
  1758. $fdate = date('Y-m-d H:i',$v['fdate']);
  1759. }
  1760. $gcdate = '';
  1761. if ($member_shop['cdate']) {
  1762. $gcdate = date('Y-m-d H:i',$member_shop['cdate']);
  1763. }
  1764. $d = array
  1765. (
  1766. $member['name'],
  1767. $member['mobile'],
  1768. $role['name'],
  1769. $fdate,
  1770. $parent_member['name'],
  1771. $parent_member['mobile'],
  1772. $g_price,
  1773. $shop['name'],
  1774. $shop['sid'],
  1775. $shop_stat,
  1776. $gcdate,
  1777. );
  1778. $body[] = $d;
  1779. }
  1780. }
  1781. }
  1782. $file = Dever::input('excel_name');
  1783. return Dever::excelExport($body, $header, $file);
  1784. }
  1785. }