Soft_cash.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. <?php
  2. namespace Agent\Lib;
  3. use Dever;
  4. Class Soft_cash
  5. {
  6. public function updateSoft($id, $name, $data){
  7. // print_R($data);die;
  8. $mobile = Dever::param('mobile', $data);
  9. $cash = Dever::param('cash', $data);
  10. $price = Dever::param('price', $data);
  11. $pic = Dever::param('pic', $data);
  12. $status = Dever::param('status', $data);
  13. $audit = Dever::param('audit', $data);
  14. $audit_desc = Dever::param('audit_desc', $data);
  15. $cdate = Dever::param('cdate',$data);
  16. $buy_cdate = Dever::param('buy_cdate',$data);
  17. $soft = Dever::db('agent/soft_cash')->one($id);
  18. $info = Dever::db('agent/member')->find(array('mobile'=>$soft['mobile']));
  19. if($info){
  20. $update['where_id'] = $id;
  21. $update['set_mid'] = $info['id'];
  22. $update['set_role'] = $info['role'];
  23. if (!$soft['order_num']) {
  24. $update['set_order_num'] = $this->getOrderId($id);
  25. }
  26. if($cash){
  27. $update['set_cash'] = $cash;
  28. } else {
  29. $cash = $soft['cash'];
  30. }
  31. if($price){
  32. $update['set_price'] = $price;
  33. }
  34. if($pic){
  35. $update['set_pic'] = $pic;
  36. }
  37. if($status){
  38. $update['set_status'] = $status;
  39. }
  40. if($audit){
  41. $update['set_audit'] = $audit;
  42. }
  43. if($audit_desc){
  44. $update['set_audit_desc'] = $audit_desc;
  45. }
  46. if($soft){
  47. if($audit == 3 ){
  48. $update['set_status'] = 4;
  49. } elseif($audit == 2){
  50. $update['set_status'] = 3;
  51. $update['set_zdate'] = time();
  52. $order['role'] = $info['role'];
  53. $order['soft_cash'] = $cash;
  54. $order['price'] = $cash;
  55. $order['cdate'] = $cdate;
  56. $order['type'] = 3;
  57. $order['sign'] = '';
  58. $order['name'] = $info['name'];
  59. $order['mobile'] = $info['mobile'];
  60. $order['mid'] = $info['id'];
  61. $order['id'] = $id;
  62. $order['area'] = $info['area'];
  63. $order['idcard'] = $info['idcard'];
  64. $order['idcard_front'] = $info['idcard_front'];
  65. $order['idcard_back'] = $info['idcard_back'];
  66. $order['company_name'] = $info['company_name'];
  67. $order['company_pic'] = $info['company_pic'];
  68. // print_R($order);die;
  69. $update['set_agreement_id'] = Dever::load('agent/lib/agreement')->up($order,1,3);
  70. }
  71. }
  72. if (!$audit) {
  73. if ($soft['status'] == 4) {
  74. $update['status'] = 2;
  75. }
  76. }
  77. if ($soft) {
  78. if ($soft['audit_admin'] <1 || !$soft['audit_admin']) {
  79. $admin = Dever::load('manage/auth.info');
  80. $update['audit_admin'] = $admin['id'];
  81. }
  82. }
  83. $ids=Dever::db('agent/soft_cash')->update($update);
  84. }
  85. }
  86. public function admin_name($id)
  87. {
  88. if ($id < 1) {
  89. return '';
  90. } else {
  91. $audit = Dever::db('manage/admin')->find($id);
  92. // print_R($audit);die;
  93. return $audit['username'];
  94. }
  95. }
  96. public function getOrderId($id)
  97. {
  98. $order = Dever::order();
  99. $info = Dever::db('agent/soft_cash')->one(array('order_num'=>$order));
  100. if ($info) {
  101. return $this->createOrderId($id);
  102. } else {
  103. return $order;
  104. }
  105. }
  106. public function soft_show($id){
  107. $info = Dever::db('agent/soft_cash')->find($id);
  108. $html['num'] = $info['order_num'].'</br>'.date('Y-m-d',$info['buy_date']).'<br/>'.date('Y-m-d',$info['cdate']);
  109. return $html;
  110. }
  111. public function show(){
  112. $id = Dever::input('id');
  113. $info = Dever::db('agent/soft_cash')->one($id);
  114. $member = Dever::db('agent/member')->one($info['mid']);
  115. $type = Dever::db('agent/member')->config['config_type'];
  116. $config_status = Dever::db('agent/soft_cash')->config['config_status'];
  117. $status = Dever::status($config_status,$info['status']);
  118. // print_R($status);die;
  119. $buy_date = date('Y-m-d H:i',$info['buy_date']);
  120. $role = Dever::db('setting/role')->one($member['role']);
  121. $area = Dever::load("area/api.string", $member['area']);
  122. $idcard_pic = '<a href="'.$member['idcard_front'].'" target="_blank"><img src="'.$member['idcard_front'].'" width="100" /></a>';
  123. if ($member['idcard_back']) {
  124. $idcard_pic .= '<a href="'.$member['idcard_back'].'" target="_blank"><img src="'.$member['idcard_back'].'" width="100" /></a>';
  125. }
  126. $picture = explode(',',$info['pic']);
  127. $pic = '';
  128. foreach ($picture as $k => $v){
  129. $pic .= '<a href="'.$v.'" target="_blank"><img src="'.$v.'" width="100" /></a>';
  130. }
  131. $result['订单信息'] = array
  132. (
  133. 'type' => 'info',
  134. 'content' => array
  135. (
  136. array
  137. (
  138. array('订单号', $info['order_num']),
  139. array('订单状态', $status),
  140. array('购买时间', $buy_date),
  141. ),
  142. array
  143. (
  144. array('备注', $info['audit_desc']),
  145. array('管理员备注', $info['admin_desc']),
  146. // array('购买时间', $buy_date),
  147. ),
  148. ),
  149. );
  150. $result['代理商信息'] = array
  151. (
  152. 'type' => 'info',
  153. 'content' => array
  154. (
  155. array
  156. (
  157. array('手机号', $member['mobile']),
  158. array('名称', $member['name']),
  159. array('类型', $type[$member['type']]),
  160. ),
  161. array
  162. (
  163. array('代理商角色', $role['name']),
  164. array('代理区域', $area),
  165. array('身份证号', $member['idcard']),
  166. ),
  167. array
  168. (
  169. array('身份证照片', $idcard_pic),
  170. ),
  171. ),
  172. );
  173. $result['费用信息'] = array
  174. (
  175. 'type' => 'info',
  176. 'content' => array
  177. (
  178. array
  179. (
  180. array('软件服务费', $info['cash']),
  181. array('原始期权价值', $info['price']),
  182. ),
  183. array
  184. (
  185. array('支付凭证', $pic),
  186. ),
  187. ),
  188. );
  189. $button = $this->show_button($info);
  190. if($info['status'] == 3 ){
  191. $member_goods = Dever::db('agent/member_agreement')->find($info['agreement_id']);
  192. if ($member_goods && $member_goods['sign']) {
  193. $sign_pic = '<a href="'.$member_goods['sign'].'" target="_blank"><img src="'.$member_goods['sign'].'" width="100" /></a>';
  194. } else {
  195. $sign_pic = '暂无';
  196. }
  197. $this->show_agreement($info, $role, $sign_pic, $result);
  198. }
  199. $head = array
  200. (
  201. 'name' => '基本信息',
  202. 'btn' => $button,
  203. );
  204. // $foot = $button;
  205. $html = Dever::show($head, $result);
  206. return $html;
  207. }
  208. public function show_button($info){
  209. $button = array();
  210. $purl = Dever::url('project/database/update?project=agent&table=soft_cash&where_id='.$info['id'].'&col=audit_desc', 'manage');
  211. $button[] = array
  212. (
  213. 'type' => 'edit',
  214. 'link' => $purl,
  215. 'name' => '备注',
  216. );
  217. $purl = Dever::url('project/database/update&project=agent&&page_type=2&table=soft_cash&menu=agent&search_option_state=1&where_id='.$info['id']);
  218. if($info['status'] < 3 || $info['status'] == 4){
  219. $button[] = array
  220. (
  221. 'type' => 'edit',
  222. 'link' => $purl,
  223. 'name' => '修改信息',
  224. );
  225. }
  226. $purl = Dever::url('project/database/update?project=agent&table=soft_cash&where_id='.$info['id'].'&audit=2&col=id,audit,audit_desc', 'manage');
  227. // if($aduit)
  228. if($info['status'] == 1){
  229. $button[] = array
  230. (
  231. 'type' => 'edit',
  232. 'link' => $purl,
  233. 'name' => '待业务初审',
  234. );
  235. }
  236. $purl = Dever::url('project/database/update?project=agent&table=soft_cash&where_id='.$info['id'].'&audit=2&col=id,audit,audit_desc', 'manage');
  237. if (Dever::load('manage/auth')->checkFunc('agent.soft_cash', 'edit1', '待财务终审')) {
  238. if($info['status'] == 2){
  239. $button[] = array
  240. (
  241. 'type' => 'edit',
  242. 'link' => $purl,
  243. 'name' => '待财务终审',
  244. );
  245. }
  246. }
  247. $purl = Dever::url('project/database/update?project=agent&table=soft_cash&where_id='.$info['id'].'&audit=3&col=id,audit,audit_desc', 'manage');
  248. if (Dever::load('manage/auth')->checkFunc('agent.soft_cash', 'edit2', '驳回')) {
  249. if($info['status'] == 4){
  250. }
  251. }
  252. if (Dever::load('manage/auth')->checkFunc('agent.soft_cash', 'close', '取消订单')) {
  253. if ($info['status'] == 4) {
  254. # 未完成审核的订单,可以随时挂起
  255. $button[] = array
  256. (
  257. 'type' => 'action',
  258. 'link' => Dever::url('lib/soft_cash.setOrderStatus?id=' . $info['id'] . '&value=4', 'agent'),
  259. 'name' => '取消订单',
  260. );
  261. }
  262. }
  263. $button[] = array
  264. (
  265. 'type' => 'link',
  266. 'link' => 'refer',
  267. 'name' => '返回上一页',
  268. );
  269. return $button;
  270. }
  271. public function setOrderStatus_api()
  272. {
  273. $where['where_id'] = Dever::input('id');
  274. $order = Dever::db('agent/soft_cash')->find($where['where_id']);
  275. if ($order) {
  276. $where['status'] = Dever::input('value');
  277. if ($where['status'] == 4) {
  278. $where['status'] = 5;
  279. $where['state'] = 2;
  280. }
  281. // print_R($where);die;
  282. Dever::db('agent/soft_cash')->update($where);
  283. }
  284. return 'reload';
  285. }
  286. private function show_agreement($info, $role, $sign_pic, &$result)
  287. {
  288. $table = array();
  289. $table['head'] = array('合同类型', '合同名称', '合同签名', '合同状态');
  290. $table['body'] = array();
  291. $agreement_type = Dever::db('setting/agreement')->config['config_type'];
  292. $agreement_status = Dever::db('agent/member_agreement')->config['status'];
  293. if($info['status'] == 3 && $info['agreement_id']){
  294. $agreement_title = '(已生成合同)';
  295. $agreement_button = array();
  296. $agreement = Dever::db('agent/member_agreement')->find(array('id' => $info['agreement_id']));
  297. if($agreement){
  298. $agreement_info = Dever::db('setting/agreement')->find($agreement['agreement_id']);
  299. // print_r($agreement_info);die;
  300. $agreement_status_name = Dever::status($agreement_status, $agreement['status']);
  301. // echo dever::sql();die;
  302. $table['body'] = array(Dever::status($agreement_type, $agreement_info['type']), Dever::load('agent/lib/agreement')->name($agreement_info, $agreement, $role, 2), $sign_pic, $agreement_status_name);
  303. }else{
  304. $agreement_title = '';
  305. }
  306. }
  307. $result['生成软件服务合同' . $agreement_title] = array
  308. (
  309. 'type' => 'table',
  310. 'head' => array('name' => '&nbsp;', 'btn' => $agreement_button),
  311. 'content' => $table
  312. );
  313. }
  314. public function insertSoft($id,$name,$data){
  315. $mobile = Dever::param('mobile',$data);
  316. $member = Dever::db('agent/member')->find(array('mobile'=>$mobile));
  317. if(!$member){
  318. Dever::alert('代理商不存在');
  319. }
  320. }
  321. public function search_api()
  322. {
  323. $value = Dever::input('value');
  324. if(!preg_match('/^1[3|5|6|7|8|9]\d{9}$/', $value)){
  325. return '代理商手机号不正确';
  326. }
  327. if ($value) {
  328. $data = Dever::db('agent/member')->one(array('mobile' => $value,'state' =>1));
  329. $table = array();
  330. $table['body'] = array();
  331. if ($data) {
  332. $info = Dever::db('agent/soft_cash')->find(array('mobile'=>$value));
  333. if ($info) {
  334. $info['buy_date'] = '<p style="color:red">'.date('Y-m-d H:i',$info['buy_date']).'</p>';
  335. $table['head'] = array('序列号', '姓名', '手机号','上次购买时间');
  336. $table['body'] = array($data['id'], $data['name'], $data['mobile'],$info['buy_date']);
  337. } else {
  338. $table['head'] = array('序列号', '姓名', '手机号');
  339. $table['body'] = array($data['id'], $data['name'], $data['mobile']);
  340. }
  341. // $table['head'] = array('序列号', '姓名', '手机号','上次购买时间');
  342. // $table['body'] = array($data['id'], $data['name'], $data['mobile']);
  343. // foreach ($data as $k => $v) {
  344. // $member = Dever::db('agent/member')->find($v['mid']);
  345. // $table['body'][] = array($k+1, $member['name'], $v['mobile']);
  346. // }
  347. $result[] = array
  348. (
  349. 'type' => 'table',
  350. 'content' => $table,
  351. );
  352. $html = Dever::show('', $result, false, false);
  353. return $html;
  354. }else{
  355. return '代理商不存在';
  356. // Dever::alert('代理商不存在');
  357. }
  358. // Dever::alert('暂无账号');
  359. // return '暂无账号';
  360. } else {
  361. return '';
  362. }
  363. }
  364. public function list($id){
  365. $info = Dever::db('agent/soft_cash')->find(array('id'=>$id));
  366. $config_status = Dever::db('agent/soft_cash')->config['config_status'];
  367. $data['status'] = Dever::status($config_status,$info['status'],true);
  368. $config_type = Dever::db('agent/soft_cash')->config['config_type'];
  369. $data['type'] = Dever::status($config_type,$info['type']);
  370. if($info['zdate']){
  371. $data['zdate'] = date('Y-m-d H:i',$info['zdate']);
  372. }else{
  373. $data['zdate'] = '-';
  374. }
  375. if($info['fdate']){
  376. $data['fdate'] = date('Y-m-d H:i',$info['fdate']);
  377. }else{
  378. $data['fdate'] = '-';
  379. }
  380. // print_R($data);die;
  381. $html = $data['status'];
  382. $html .= '<br />' . $data['type'];
  383. $html .= '<br />' . $data['zdate'];
  384. $html .= '<br />' . $data['fdate'];
  385. return $html;
  386. }
  387. #数据导出
  388. public function out_soft_cash_api($data){
  389. $header = array('合同乙方', '手机号码', '身份证号码','合同总期数(年)', '合同类型', '签订日期', '合同金额', '购买日期', '录入日期', '终审日期');
  390. $body = array();
  391. $agreement_name = '';
  392. foreach($data as $k => $v){
  393. $member = Dever::db('agent/member')->find($v['mid']);
  394. $role = Dever::db('setting/role')->find($member['role']);
  395. $agreement = Dever::db('agent/member_agreement')->find(array('id'=>$v['agreement_id'],'mid'=>$v['mid']));
  396. if($agreement && $agreement['agreement_id']){
  397. $name = Dever::db('setting/agreement')->find(array('id'=>$agreement['agreement_id']));
  398. $config_type= Dever::db('setting/agreement')->config['config_type'];
  399. $agreement_name = Dever::status($config_type,$name['type']);
  400. }
  401. $type = 2;
  402. # 这里加判断
  403. if ($role['type'] == 2 && $role['area'] == 1) {
  404. $type = 1;
  405. } elseif ($v['cash'] > 6000 && $v['cash'] <= 30000 && $v['cash']%5000 == 0) {
  406. $type = 3;
  407. } elseif ($v['cash'] <= 6000 && $v['cash']%1000 == 0) {
  408. $type = 4;
  409. } else {
  410. $type = 2;
  411. }
  412. # 城市代理
  413. if ($type == 1) {
  414. $name = '城市代理版';
  415. $year = 1;
  416. }
  417. # 定制版
  418. elseif ($type == 2) {
  419. $name = '定制版';
  420. $year = 1;
  421. }
  422. # 升级版
  423. elseif ($type == 3) {
  424. $name = '升级版';
  425. $year = intval($v['cash']/5000);
  426. if ($year > 6) {
  427. $year = 6;
  428. }
  429. }
  430. # 基础版
  431. else {
  432. $name = '基础版';
  433. $year = intval($v['cash']/1000);
  434. if ($year > 6) {
  435. $year = 6;
  436. }
  437. }
  438. if($v['fdate']){
  439. $fdate = date('Y-m-d H:i',$v['fdate']);
  440. }else{
  441. $fdate = '-';
  442. }
  443. if($v['buy_date']){
  444. $buy_date = date('Y-m-d H:i',$v['buy_date']);
  445. }else{
  446. $buy_date = '-';
  447. }
  448. if($v['zdate']){
  449. $zdate = date('Y-m-d H:i',$v['zdate']);
  450. }else{
  451. $zdate = '-';
  452. }
  453. if($v['cdate']){
  454. $cdate = date('Y-m-d H:i',$v['cdate']);
  455. }else{
  456. $cdate = '-';
  457. }
  458. $d = array
  459. (
  460. $member['name'],
  461. $v['mobile'],
  462. $member['idcard'],
  463. $year,
  464. $name,
  465. $fdate,
  466. $v['cash'],
  467. $buy_date,
  468. $cdate,
  469. $zdate,
  470. );
  471. $body[] = $d;
  472. }
  473. $file = Dever::input('excel_name');
  474. return Dever::excelExport($body, $header, $file);
  475. }
  476. public function update_role_api(){
  477. $data = Dever::db('agent/soft_cash')->state();
  478. foreach($data as $k => $v){
  479. if(!$v['role']){
  480. $member = Dever::db('agent/member')->find($v['mid']);
  481. $where['where_id'] = $v['id'];
  482. $where['set_role'] = $member['role'];
  483. Dever::db('agent/soft_cash')->update($where);
  484. }
  485. if(!$v['fdate'] && $v['status'] == 3){
  486. $agreement = Dever::db('agent/member_agreement')->find(array('id'=>$v['agreement_id'],'mid'=>$v['mid']));
  487. $where['where_id'] = $v['id'];
  488. $where['set_type'] = $agreement['status'];
  489. $where['set_zdate'] = $agreement['qdate'];
  490. $where['set_fdate'] = $agreement['qdate'];
  491. Dever::db('agent/soft_cash')->update($where);
  492. }
  493. }
  494. }
  495. }