Soft_cash.php 19 KB

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