Sell.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <?php
  2. namespace Bill\Lib;
  3. use Dever;
  4. class Sell
  5. {
  6. # 发放业绩
  7. public function push_one_commit($mid, $num, $role, $id, $desc, $cdate = false)
  8. {
  9. $this->push($mid, $num, $role, $id, $desc, $cdate);
  10. }
  11. # 批量发放业绩
  12. public function push_all_commit($mid, $num, $role, $id, $desc, $cdate = false)
  13. {
  14. $this->push($mid, $num, $role, $id, $desc, $cdate);
  15. $parent = Dever::load('invite/api')->getParentAll($mid);
  16. if ($parent) {
  17. foreach ($parent as $k => $v) {
  18. $this->push($v['uid'], $num, $role, $id, $desc, $cdate);
  19. }
  20. }
  21. }
  22. # 发放业绩
  23. private function push($mid, $num, $role, $id, $desc, $cdate = false)
  24. {
  25. $this->up(false, $mid, 1, $num, $role, $id, $desc, 2, $cdate);
  26. $this->up(false, $mid, 2, $num, $role, $id, $desc, 2, $cdate);
  27. $where['where_id'] = $mid;
  28. $where['group_sell'] = $num;
  29. $where['sell'] = $num;
  30. return Dever::db('agent/member')->upGroupSellOne($where);
  31. }
  32. # 更新数据
  33. public function up($child, $mid, $type, $num, $role, $type_id, $desc, $stype = 1, $cdate = false)
  34. {
  35. if ($num == 0) {
  36. return;
  37. }
  38. if ($type > 2) {
  39. return;
  40. }
  41. $member = Dever::db('agent/member')->find(array('id' => $mid, 'clear' => true));
  42. if ($member && $member['status'] <= 2) {
  43. $desc = explode(',', $desc);
  44. $desc = $desc[0];
  45. $where['mid'] = $mid;
  46. $where['type'] = $type;
  47. $where['stype'] = $stype;
  48. $where['type_id'] = $type_id;
  49. $where['clear'] = true;
  50. $info = Dever::db('bill/sell')->find($where);
  51. if (!$info) {
  52. $data = $where;
  53. if ($child && isset($child['id'])) {
  54. $child_mid = Dever::load('invite/api')->getRelation($child['id'], $mid);
  55. if ($child_mid) {
  56. $data['child_mid'] = $child_mid;
  57. }
  58. }
  59. if ($cdate) {
  60. $data['cdate'] = $cdate;
  61. }
  62. $data['order_num'] = $this->getOrderId();
  63. $data['num'] = $num;
  64. $data['role'] = $role;
  65. $data['desc'] = $desc;
  66. return Dever::db('bill/sell')->insert($data);
  67. }
  68. return $info['id'];
  69. }
  70. return false;
  71. }
  72. /**
  73. * 生成订单号
  74. *
  75. * @return mixed
  76. */
  77. public function getOrderId()
  78. {
  79. $where['order_num'] = Dever::order('S');
  80. $state = Dever::db('bill/sell')->one($where);
  81. if (!$state) {
  82. return $where['order_num'];
  83. } else {
  84. return $this->getOrderId();
  85. }
  86. }
  87. # 展示详情
  88. public function show()
  89. {
  90. $id = Dever::input('id');
  91. $config = Dever::db('bill/sell')->config['set'];
  92. $info = Dever::db('bill/sell')->one($id);
  93. $type = $config['type'][$info['type']];
  94. $member = Dever::db('agent/member')->find($info['mid']);
  95. $role = Dever::db('setting/role')->one($member['role']);
  96. $level = Dever::db('setting/level')->one($member['level_id']);
  97. if ($member['shop_id']) {
  98. $shop = Dever::db('shop/info')->one($member['shop_id']);
  99. } else {
  100. $shop['id'] = -1;
  101. $shop['name'] = '无';
  102. }
  103. $cdate = date('Y-m-d H:i', $info['cdate']);
  104. $result = array();
  105. $result['代理商信息'] = array
  106. (
  107. 'type' => 'info',
  108. 'content' => array
  109. (
  110. array
  111. (
  112. array('代理商', $member['name'] . ' ' . $member['mobile']),
  113. array('代理角色', $role['name'] . ($level ? '('.$level['name'].')' : '')),
  114. array('所属店铺', $shop['name']),
  115. ),
  116. array
  117. (
  118. array('资金余额', '¥' . $member['cash'] . '元'),
  119. //array('直推业绩', '¥' . $member['sell'] . '元'),
  120. array('团队业绩', '¥' . $member['group_sell'] . '元'),
  121. ),
  122. ),
  123. );
  124. $result['业绩信息'] = array
  125. (
  126. 'type' => 'info',
  127. 'content' => array
  128. (
  129. array
  130. (
  131. array('流水号', $info['order_num']),
  132. array('交易时间', $cdate),
  133. array('业绩类型', $type),
  134. ),
  135. array
  136. (
  137. array('业绩金额', '¥' . $info['num'] . '元'),
  138. array('业绩说明', $info['desc']),
  139. ),
  140. )
  141. );
  142. $head_btn[] = array
  143. (
  144. 'type' => 'link',
  145. 'link' => Dever::url('project/database/list?project=bill&table=sell&menu=bill&search_option_state=1', 'manage'),
  146. 'name' => '返回上一页',
  147. );
  148. $head = array
  149. (
  150. 'name' => '基本信息',
  151. 'btn' => $head_btn,
  152. );
  153. // $head = array
  154. // (
  155. // 'name' => '基本信息',
  156. // 'btn' => array(),
  157. // );
  158. $html = Dever::show($head, $result);
  159. return $html;
  160. }
  161. public function out_sell($data){
  162. $header = array('代理商姓名', '代理商手机号','代理商角色','代理区域', '下级姓名', '下级手机号', '业绩金额', '下单时间');
  163. $body = array();
  164. foreach($data as $k => $v){
  165. $member = Dever::db('agent/member')->find($v['mid']);
  166. $role = Dever::db('setting/role')->find($member['role']);
  167. $area = Dever::load("area/api.string", $member['area'], '-', true, '');
  168. $child_name = '';
  169. $child_mobile = '';
  170. if($v['child_mid'] && $v['child_mid'] > 0){
  171. $child = Dever::db('agent/member')->find($v['child_mid']);
  172. $child_name = $child['name'];
  173. $child_mobile = $child['mobile'];
  174. }
  175. $cdate = '-';
  176. if($v['cdate']){
  177. $cdate = date('Y-m-d H:i',$v['cdate']);
  178. }
  179. $d = array
  180. (
  181. $member['name'],
  182. $member['mobile'],
  183. $role['name'],
  184. $area,
  185. $child_name,
  186. $child_mobile,
  187. $v['num'],
  188. $cdate,
  189. );
  190. $body[] = $d;
  191. }
  192. $file = Dever::input('excel_name');
  193. return Dever::excelExport($body, $header, $file);
  194. }
  195. }