Order.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace Active\Lib;
  3. use Dever;
  4. Class Order
  5. {
  6. #更新数量
  7. public function upNum($order_id)
  8. {
  9. $data = Dever::db('active/order')->find($order_id);
  10. if (!$data['refund_num']) {
  11. $w['refund_num'] = 0;
  12. } else {
  13. $w['refund_num'] =$data['refund_num'];
  14. }
  15. if (!$data['code_num'] || $data['code_num'] < 0) {
  16. $w['code_num'] = 0;
  17. }
  18. if (!$data['no_num']) {
  19. $w['no_num'] = 0;
  20. }
  21. #已使用的数量
  22. $code = Dever::db('active/code')->getCode(array('order_id'=>$data['id'],'status'=>'1,2'));
  23. $w['code_num'] = count($code);
  24. #待核销的数量
  25. $no_code = Dever::db('active/code')->getCode(array('order_id'=>$data['id'],'status'=>1));
  26. $w['no_num'] = count($no_code);
  27. $w['where_id'] = $data['id'];
  28. Dever::db('active/order')->update($w);
  29. }
  30. #生成核销码
  31. public function insertCode($id,$name,$data)
  32. {
  33. $active_id = Dever::param('active_id',$data);
  34. $content = Dever::param('content',$data);
  35. $contents = Dever::split($content);
  36. $active = Dever::db('active/info')->find($active_id);
  37. if ($contents) {
  38. foreach ($contents as $k => $v) {
  39. $user = Dever::db('active/user')->find(array('mobile'=>$v,'clear'=>true));
  40. // print_R($user);die;
  41. if ($user) {
  42. $member = Dever::load('active/lib/user')->agent($user);
  43. $code = Dever::db('active/code')->getOne(array('active_id'=>$active_id,'join_uid'=>$user['id'],'status'=>'1,2','clear'=>true));
  44. if ($code) {
  45. Dever::alert('您已领取过了');
  46. }
  47. }
  48. }
  49. }
  50. }
  51. public function createCode($id,$name,$data)
  52. {
  53. $active_id = Dever::param('active_id',$data);
  54. $content = Dever::param('content',$data);
  55. $contents = Dever::split($content);
  56. $active = Dever::db('active/info')->find($active_id);
  57. if ($contents) {
  58. foreach ($contents as $k => $v) {
  59. $user = Dever::db('active/user')->find(array('mobile'=>$v,'clear'=>true));
  60. if ($user) {
  61. $member = Dever::load('active/lib/user')->agent($user);
  62. if ($member && $active['status'] == 2) {
  63. $this->user($active_id,$user['id']);
  64. }
  65. } else {
  66. $member = Dever::db('agent/member')->find(array('mobile'=>$v));
  67. if ($member) {
  68. $insert['name'] = $member['name'];
  69. $insert['mobile'] = $v;
  70. $insert['idcard'] = $member['idcard'];
  71. $insert['pass'] = $member['password'];
  72. $insert['old_pwd'] = $member['old_pwd'];
  73. $insert['old_salt'] = $member['old_salt'];
  74. $uid = Dever::db('active/user')->insert($insert);
  75. $this->user($active_id,$uid);
  76. } else {
  77. $insert['name'] = substr($v, 0, 3).'****'.substr($v, 7);
  78. $insert['mobile'] = $v;
  79. $uid = Dever::db('active/user')->insert($insert);
  80. $this->user($active_id,$uid);
  81. }
  82. }
  83. }
  84. return 'ok';
  85. }
  86. }
  87. private function user($active_id,$uid)
  88. {
  89. $w['active_id'] = $active_id;
  90. $w['join_uid'] = $uid;
  91. $w['write_code'] = Dever::load('active/home')->getCode();
  92. $w['type'] = 2;
  93. if ($uid && $uid >=1) {
  94. Dever::db('active/code')->insert($w);
  95. }
  96. // Dever::db('active/creat_code')->insert($w);
  97. }
  98. }