SharebonusController.class.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. * ==========================================================================
  6. * @link http://www.liofis.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license http://www.liofis.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fish
  12. * 处理订单相关内容
  13. */
  14. namespace Home\Controller;
  15. class SharebonusController extends CommonController {
  16. protected function _initialize()
  17. {
  18. parent::_initialize();
  19. $this->cur_page = 'sharebonus';
  20. }
  21. /**
  22. 获取佣金首页
  23. **/
  24. function tuanbonus_index()
  25. {
  26. $member_id = is_login();
  27. $member_info = M('member')->where( array('member_id' => $member_id) )->find();
  28. //sum_member_commiss($where = array())
  29. $member_model = D('Home/Member');
  30. //今日收入
  31. $today_begin_time = strtotime( date('Y-m-d'.' 00:00:00') );
  32. $today_end_time = $today_begin_time + 86400;
  33. //$map['id'] = array('between','1,8'); $map['id'] = array('neq',100);
  34. $today_where = array();
  35. $today_where['member_id'] = $member_id;
  36. $today_where['state'] = array('neq',2);
  37. $today_where['addtime'] = array('between',$today_begin_time.','.$today_end_time);
  38. $today_commiss = $member_model->sum_member_fen_commiss($today_where);
  39. //本月收入
  40. $month_begin_time = strtotime( date("Y-m-d ",mktime(0, 0 , 0,date("m"),1,date("Y"))).' 00:00:00' );
  41. $month_end_time = strtotime( date("Y-m-d ",mktime(23,59,59,date("m"),date("t"),date("Y"))).' 00:00:00' ) +86400;
  42. $month_where = array();
  43. $month_where['member_id'] = $member_id;
  44. $month_where['state'] = array('neq',2);
  45. $month_where['addtime'] = array('between',$month_begin_time.','.$month_end_time);
  46. $month_commiss = $member_model->sum_member_fen_commiss($month_where);
  47. //累计收入
  48. $total_where = array();
  49. $total_where['member_id'] = $member_id;
  50. $total_where['state'] = array('neq',2);
  51. $total_commiss = $member_model->sum_member_fen_commiss($total_where);
  52. //待确认收入
  53. $total_wait_where = array();
  54. $total_wait_where['member_id'] = $member_id;
  55. $total_wait_where['state'] = 0;
  56. $total_wait_commiss = $member_model->sum_member_fen_commiss($total_wait_where);
  57. //可提现金额
  58. $member_commiss = M('member_sharing')->where( array('member_id' => $member_id) )->find();
  59. $this->today_commiss = round($today_commiss, 2);
  60. $this->month_commiss = round($month_commiss, 2);
  61. $this->total_commiss = round($total_commiss, 2);
  62. $this->total_wait_commiss = round($total_wait_commiss, 2);
  63. $can_tixian_money = 0;
  64. if(!empty($member_commiss)) {
  65. $can_tixian_money = $member_commiss['money'];
  66. }
  67. $this->can_tixian_money = round($can_tixian_money, 2);
  68. $comsiss_flag = $member_info['comsiss_flag'];
  69. $this->comsiss_flag = $comsiss_flag;
  70. $need_data = array();
  71. $need_data['today_commiss'] = round($today_commiss, 2);
  72. $need_data['month_commiss'] = round($month_commiss, 2);
  73. $need_data['total_commiss'] = round($total_commiss, 2);
  74. $need_data['total_wait_commiss'] = round($total_wait_commiss, 2);
  75. $need_data['can_tixian_money'] = round($can_tixian_money, 2);
  76. $need_data['comsiss_flag'] = $comsiss_flag;
  77. //echo json_encode( array('code' =>0, 'data' => $need_data ) );
  78. //die();
  79. $this->display('index');
  80. }
  81. /**
  82. 获取账单详情
  83. **/
  84. public function listorder()
  85. {
  86. $member_id = is_login();
  87. $per_page = 6;
  88. $page = I('post.page',1);
  89. $offset = ($page - 1) * $per_page;
  90. $list = array();
  91. $where = '';
  92. $state = I('get.state',-1);
  93. //state
  94. if($state >=0)
  95. {
  96. $where = ' and mco.state = '.$state;
  97. }
  98. $this->state = $state;
  99. $sql = 'select mco.money,mco.child_member_id,mco.addtime,mco.state,o.order_status_id,o.order_num_alias,o.total,og.goods_id,og.quantity,og.name,mco.store_id,m.uname from
  100. '.C('DB_PREFIX')."member_sharing_order as mco , ".C('DB_PREFIX')."order_goods as og, ".C('DB_PREFIX')."order as o ,
  101. ".C('DB_PREFIX')."member as m
  102. where mco.order_id=og.order_id and mco.order_id = o.order_id and m.member_id=mco.child_member_id and mco.member_id=".$member_id." {$where} order by mco.id desc limit {$offset},{$per_page}";
  103. $list = M()->query($sql);
  104. $order_status_list = M('order_status')->select();
  105. $status_arr = array();
  106. foreach($order_status_list as $vv)
  107. {
  108. $status_arr[$vv['order_status_id']] = $vv['name'];
  109. }
  110. foreach($list as $key =>$val)
  111. {
  112. $val['total'] = round($val['total'],2);
  113. $val['money'] = round($val['money'],2);
  114. $val['status_name'] = $status_arr[$val['order_status_id']];
  115. $val['addtime'] = date('Y-m-d', $val['addtime']);
  116. $goods_info = M('goods')->field('image')->where( array('goods_id' => $val['goods_id']) )->find();
  117. $val['image']=resize($goods_info['image'], C('common_image_thumb_width'), C('common_image_thumb_height'));
  118. $list[$key] = $val;
  119. }
  120. $this->list = $list;
  121. if($page > 1) {
  122. $result = array('code' => 0);
  123. if(!empty($list)) {
  124. $result['code'] = 1;
  125. $result['html'] = $this->fetch('Sharebonus:listorder_ajax_fetch');
  126. }
  127. echo json_encode($result);
  128. die();
  129. }
  130. //今日新增
  131. $today_begin_time = strtotime( date('Y-m-d'.' 00:00:00') );
  132. $today_end_time = $today_begin_time + 86400;
  133. $today_where = array();
  134. $today_where['member_id'] = $member_id;
  135. $today_where['addtime'] = array('between',$today_begin_time.','.$today_end_time);
  136. $today_count = M('member_sharing_order')->where( $today_where )->count();
  137. //昨日新增
  138. $yes_begin_time = $today_begin_time - 86400;
  139. $yes_end_time = $today_begin_time;
  140. $yes_where = array();
  141. $yes_where['member_id'] = $member_id;
  142. $yes_where['addtime'] = array('between',$yes_begin_time.','.$yes_end_time);
  143. $yes_count = M('member_sharing_order')->where( $yes_where )->count();
  144. //总订单量
  145. $total_where = array();
  146. $total_where['member_id'] = $member_id;
  147. $total_count = M('member_sharing_order')->where( $total_where )->count();
  148. $need_data = array();
  149. $need_data['today_count'] = $today_count;
  150. $need_data['yes_count'] = $yes_count;
  151. $need_data['total_count'] = $total_count;
  152. $this->today_count = $today_count;
  153. $this->yes_count = $yes_count;
  154. $this->total_count = $total_count;
  155. $this->display();
  156. }
  157. /**
  158. 获取账单详情列表
  159. **/
  160. public function listorder_list()
  161. {
  162. $member_id = is_login();
  163. $member_info = M('member')->where( array('member_id' => $member_id) )->find();
  164. $per_page = 6;
  165. $page = I('get.page',1);
  166. $offset = ($page - 1) * $per_page;
  167. $list = array();
  168. $where = '';
  169. $state = I('get.state',-1);
  170. //state
  171. if($state >=0)
  172. {
  173. $where = ' and mco.state = '.$state;
  174. }
  175. $commiss_level_num = C('commiss_level_num');
  176. $where = ' and mco.level <= '.$commiss_level_num;
  177. //$commiss_level_num = C('commiss_level_num'); level
  178. $this->state = $state;
  179. $sql = 'select mco.level, mco.money,mco.child_member_id,mco.addtime,mco.state,o.order_status_id,o.order_num_alias,o.total,og.goods_id,og.quantity,og.name,mco.store_id,m.uname from '.C('DB_PREFIX')."member_commiss_order as mco , ".C('DB_PREFIX')."order_goods as og, ".C('DB_PREFIX')."order as o , ".C('DB_PREFIX')."member as m
  180. where mco.order_id=og.order_id and mco.order_id = o.order_id and m.member_id=mco.child_member_id and mco.member_id=".$member_id." {$where} order by mco.id desc limit {$offset},{$per_page}";
  181. $list = M()->query($sql);
  182. $order_status_list = M('order_status')->select();
  183. $status_arr = array();
  184. foreach($order_status_list as $vv)
  185. {
  186. $status_arr[$vv['order_status_id']] = $vv['name'];
  187. }
  188. foreach($list as $key =>$val)
  189. {
  190. $val['total'] = round($val['total'],2);
  191. $val['money'] = round($val['money'],2);
  192. $val['status_name'] = $status_arr[$val['order_status_id']];
  193. $val['addtime'] = date('Y-m-d', $val['addtime']);
  194. $goods_info = M('goods')->field('image')->where( array('goods_id' => $val['goods_id']) )->find();
  195. $val['image']=C('SITE_URL'). resize($goods_info['image'], C('common_image_thumb_width'), C('common_image_thumb_height'));
  196. $list[$key] = $val;
  197. }
  198. $this->list = $list;
  199. if(empty($list))
  200. {
  201. echo json_encode( array('code' => 1) );
  202. die();
  203. }else {
  204. echo json_encode( array('code' => 0, 'data' => $list) );
  205. die();
  206. }
  207. }
  208. /**
  209. 检测是否绑定了银行卡
  210. **/
  211. public function check_tixian()
  212. {
  213. $token = I('get.token');
  214. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  215. $member_id = $weprogram_token['member_id'];
  216. $member_info = M('member')->where( array('member_id' => $member_id) )->find();
  217. $member_commiss = M('member_commiss')->where( array('member_id' => $member_id) )->find();
  218. if( empty($member_commiss['bankname']) || empty($member_commiss['bankaccount']) || empty($member_commiss['bankusername']))
  219. {
  220. echo json_encode( array('code' =>0) );
  221. die();
  222. }else{
  223. echo json_encode( array('code' => 1) );
  224. die();
  225. }
  226. }
  227. /**
  228. 获取用户佣金信息
  229. **/
  230. public function get_tixian_info()
  231. {
  232. $token = I('get.token');
  233. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  234. $member_id = $weprogram_token['member_id'];
  235. $limit_money = C('commiss_money_limit');
  236. $member_info = M('member')->where( array('member_id' => $member_id) )->find();
  237. $member_commiss = M('member_commiss')->where( array('member_id' => $member_id) )->find();
  238. $member_commiss['limit_money'] = $limit_money;
  239. echo json_encode( array('code' =>0,'data' => $member_commiss) );
  240. die();
  241. }
  242. public function bindcard()
  243. {
  244. $bankusername = I('post.bankusername','','htmlspecialchars');
  245. $bankname = I('post.bankname','','htmlspecialchars');
  246. $bankaccount = I('post.bankaccount','','htmlspecialchars');
  247. $data = array();
  248. $data['bankusername'] = $bankusername;
  249. $data['bankname'] = $bankname;
  250. $data['bankaccount'] = $bankaccount;
  251. M('member_sharing')->where( array('member_id' => is_login() ) )->save($data);
  252. $this->redirect('Sharebonus/tixian');
  253. }
  254. public function tixian()
  255. {
  256. $member_id = is_login();
  257. $member_info = M('member')->where( array('member_id' => $member_id) )->find();
  258. if($member_info['comsiss_flag'] != 1)
  259. {
  260. die();
  261. }
  262. $member_commiss = M('member_sharing')->where( array('member_id' => $member_id) )->find();
  263. $this->member_commiss = $member_commiss;
  264. if( empty($member_commiss['bankname']) || empty($member_commiss['bankaccount']) || empty($member_commiss['bankusername']))
  265. {
  266. $this->display();
  267. } else {
  268. $per_page = 5;
  269. $page = I('post.page',1);
  270. $offset = ($page - 1) * $per_page;
  271. $list = array();
  272. $sql = "select * from ".C('DB_PREFIX')."fen_tixian_order
  273. where member_id=".$member_id." order by addtime desc limit {$offset},{$per_page}";
  274. $list = M()->query($sql);
  275. $this->list = $list;
  276. if($page > 1) {
  277. $result = array('code' => 0);
  278. if(!empty($list)) {
  279. $result['code'] = 1;
  280. $result['html'] = $this->fetch('Sharebonus:tixianorder_ajax_fetch');
  281. }
  282. echo json_encode($result);
  283. die();
  284. }
  285. $commiss_money_limit = C('commiss_money_limit');
  286. $this->commiss_money_limit = $commiss_money_limit;
  287. $this->display('tixianorder');
  288. }
  289. }
  290. public function tixian_sub()
  291. {
  292. $member_id = is_login();
  293. $money = I('post.money',0,'floatval');
  294. $result = array('code' => 0,'msg' => '提现失败');
  295. $member_commiss = M('member_sharing')->where( array('member_id' => $member_id ) )->find();
  296. $member_info = M('member')->where( array('member_id' =>$member_id ) )->find();
  297. $commiss_money_limit = C('commiss_money_limit');
  298. if(!empty($commiss_money_limit) && $commiss_money_limit >0)
  299. {
  300. if($member_commiss['money'] < $commiss_money_limit)
  301. {
  302. $result['msg'] = '佣金满'.$commiss_money_limit.'才能提现';
  303. echo json_encode($result);
  304. die();
  305. }
  306. }
  307. if($money > 0 && $money <= $member_commiss['money'])
  308. {
  309. $data = array();
  310. $data['member_id'] = $member_id;
  311. $data['money'] = $money;
  312. $data['state'] = 0;
  313. $data['shentime'] = 0;
  314. $data['addtime'] = time();
  315. M('fen_tixian_order')->add($data);
  316. $com_arr = array();
  317. $com_arr['money'] = $member_commiss['money'] - $money;
  318. $com_arr['dongmoney'] = $member_commiss['dongmoney'] + $money;
  319. M('member_sharing')->where( array('member_id' => $member_id) )->save($com_arr);
  320. $result['code'] = 1;
  321. }
  322. echo json_encode($result);
  323. die();
  324. }
  325. /**
  326. 提现记录
  327. **/
  328. public function tixian_record()
  329. {
  330. $token = I('get.token');
  331. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  332. $member_id = $weprogram_token['member_id'];
  333. $member_info = M('member')->where( array('member_id' => $member_id) )->find();
  334. $per_page = 5;
  335. $page = I('get.page',1);
  336. $offset = ($page - 1) * $per_page;
  337. $list = array();
  338. $sql = "select * from ".C('DB_PREFIX')."fen_tixian_order
  339. where member_id=".$member_id." order by addtime desc limit {$offset},{$per_page}";
  340. $list = M()->query($sql);
  341. foreach($list as $key => $val)
  342. {
  343. $val['addtime'] = date('Y-m-d', $val['addtime']);
  344. $list[$key] = $val;
  345. }
  346. if( !empty($list) )
  347. {
  348. echo json_encode( array('code' =>0, 'data'=>$list) );
  349. die();
  350. }else{
  351. echo json_encode( array('code' => 1) );
  352. die();
  353. }
  354. }
  355. public function cons_member_common($member_id)
  356. {
  357. $member_common = array('member_id'=>$member_id,'qrcode_img' => '');
  358. M('member_common')->add($member_common);
  359. return $member_common;
  360. }
  361. /**
  362. 团长二维码
  363. **/
  364. public function qrcode()
  365. {
  366. $member_id = is_login();
  367. $member_common = M('member_common')->where( array('member_id' => is_login()) )->find();
  368. if(empty($member_common))
  369. {
  370. $member_common = $this->cons_member_common($member_id);
  371. }
  372. $is_tan = 1;
  373. $hashids = new \Lib\Hashids(C('PWD_KEY'), C('URL_ID'));
  374. $hash_member_id = $hashids->encode($member_id);
  375. $url = C('SITE_URL')."index.php?s=/index/index/rmid/{$hash_member_id}";
  376. if(empty($member_common['qrcode_img']))
  377. {
  378. $content = $url;
  379. $target = C('SITE_URL').'Uploads/image/'.C('user_qrcode_image');
  380. $user_qrcodebg_x = C('user_qrcode_x');
  381. $user_qrcodebg_y = C('user_qrcode_y');
  382. if(empty($user_qrcodebg_x))
  383. {
  384. $user_qrcodebg_x = 0;
  385. }
  386. if(empty($user_qrcodebg_y))
  387. {
  388. $user_qrcodebg_y = 0;
  389. }
  390. $new_image = get_compare_qrcode($content,$target,$user_qrcodebg_x,$user_qrcodebg_y);
  391. $uarray = array( 'qrcode_img'=>$new_image);
  392. M('member_common')->where( array('member_id' => $member_id) )->save($uarray);
  393. $member_common['qrcode_img'] = $new_image;
  394. cookie('qrcode_tan', 1);
  395. } else {
  396. $tan_time = cookie('qrcode_tan');
  397. if(empty($tan_time))
  398. {
  399. cookie('qrcode_tan', 1);
  400. }else
  401. {
  402. cookie('qrcode_tan', $tan_time+1);
  403. if($tan_time >=2)
  404. {
  405. $is_tan = 2;
  406. }
  407. }
  408. $new_image = $login_user['qrcode'];
  409. }
  410. $this->member_common = $member_common;
  411. $this->display();
  412. }
  413. function tuanyuan()
  414. {
  415. $member_id = is_login();
  416. //$member_id = 599;
  417. //$token = I('get.token');
  418. //$weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  419. // $member_id = $weprogram_token['member_id'];
  420. $member_info = M('member')->where( array('member_id' => $member_id) )->find();
  421. $per_page = 6;
  422. $page = I('get.page',1);
  423. $offset = ($page - 1) * $per_page;
  424. //type 1 2 3
  425. $type = I('get.type',1);
  426. //6
  427. $list = array();
  428. if($type == 1)
  429. {
  430. $sql = 'select * from '.C('DB_PREFIX')."member
  431. where share_id = ".$member_id." order by member_id desc limit {$offset},{$per_page}";
  432. $list = M()->query($sql);
  433. //var_dump($list, $sql);die();
  434. }else if( $type ==2 ){
  435. $sql = 'select member_id from '.C('DB_PREFIX')."member
  436. where share_id = ".$member_id;
  437. $first_list = M()->query($sql);
  438. $list = array();
  439. if( !empty($first_list) )
  440. {
  441. $ids_arr = array();
  442. foreach( $first_list as $val )
  443. {
  444. $ids_arr[] = $val['member_id'];
  445. }
  446. $ids_str = implode(',', $ids_arr);
  447. $sql = 'select * from '.C('DB_PREFIX')."member
  448. where share_id in (".$ids_str.") order by member_id desc limit {$offset},{$per_page}";
  449. $list = M()->query($sql);
  450. }
  451. } else if( $type ==3 ){
  452. $sql = 'select member_id from '.C('DB_PREFIX')."member
  453. where share_id = ".$member_id;
  454. $first_list = M()->query($sql);
  455. $list = array();
  456. if( !empty($first_list) )
  457. {
  458. $ids_arr = array();
  459. foreach( $first_list as $val )
  460. {
  461. $ids_arr[] = $val['member_id'];
  462. }
  463. $ids_str = implode(',', $ids_arr);
  464. $sql = 'select member_id from '.C('DB_PREFIX')."member
  465. where share_id in (".$ids_str.") ";
  466. $second_list = M()->query($sql);
  467. if( !empty($second_list) )
  468. {
  469. $ids_arr = array();
  470. foreach( $second_list as $val )
  471. {
  472. $ids_arr[] = $val['member_id'];
  473. }
  474. $ids_str = implode(',', $ids_arr);
  475. $sql = 'select * from '.C('DB_PREFIX')."member
  476. where share_id in (".$ids_str.") order by member_id desc limit {$offset},{$per_page}";
  477. $list = M()->query($sql);
  478. }
  479. }
  480. }
  481. //{$member_info.uname}
  482. foreach($list as $key => $val)
  483. {
  484. $parent_name = M('member')->field('name')->where( array('member_id' => $val['share_id']) )->find();
  485. $val['parent_name'] = $parent_name['name'];
  486. $val['create_time'] = date('Y-m-d H:i:s', $val['create_time']);
  487. $list[$key] = $val;
  488. }
  489. $this->type = $type;
  490. $this->list = $list;
  491. /**
  492. if( empty($list) )
  493. {
  494. echo json_encode( array('code' => 1) );
  495. die();
  496. } else{
  497. echo json_encode( array('code' =>0 , 'data' => $list) );
  498. die();
  499. }
  500. **/
  501. if($page > 1) {
  502. $result = array('code' => 0);
  503. if(!empty($list)) {
  504. $result['code'] = 1;
  505. $result['html'] = $this->fetch('Tuanbonus:tuanyuan_ajax_fetch');
  506. }
  507. echo json_encode($result);
  508. die();
  509. }
  510. $this->display();
  511. }
  512. public function yongjing()
  513. {
  514. $per_page = 10;
  515. $page = I('get.page',1);
  516. $gid = I('get.gid',0);
  517. $offset = ($page - 1) * $per_page;
  518. $where = "";
  519. //danprice pin_price
  520. if( !empty($gid) && $gid >0 )
  521. {
  522. $goods_ids_arr = M('goods_to_category')->where("class_id1 ={$gid} or class_id2 ={$gid} or class_id3 = {$gid} ")->field('goods_id')->select();
  523. $ids_arr = array();
  524. foreach($goods_ids_arr as $val){
  525. $ids_arr[] = $val['goods_id'];
  526. }
  527. $ids_str = implode(',',$ids_arr);
  528. if( !empty($ids_str) )
  529. {
  530. $where .= " and a.goods_id in ({$ids_str}) ";
  531. //a.goods_id
  532. }
  533. }
  534. $sql = " SELECT a.goods_id,a.name,a.quantity,a.danprice,b.pin_price,a.commiss_one_dan_disc,( b.commiss_one_pin_disc * b.pin_price ) as pin_yong_money,( a.commiss_one_dan_disc * a.danprice ) as dan_yong_money, a.price,a.image
  535. FROM ".C('DB_PREFIX')."goods as a left join ".C('DB_PREFIX')."pin_goods as b on a.goods_id = b.goods_id WHERE (a.commiss_one_dan_disc >0 or b.commiss_one_pin_disc >0) and a.status = 1 {$where} and a.quantity >0 order by dan_yong_money desc, pin_yong_money desc
  536. limit {$offset},{$per_page}";
  537. /**
  538. $sql = 'select g.goods_id,g.name,g.quantity,g.pinprice,g.commiss_one_pin_disc,( g.pinprice * g.commiss_one_pin_disc ) as yong_money, g.price,g.image from '.C('DB_PREFIX')."goods as g
  539. where g.status =1 and g.quantity > 0 and g.commiss_one_pin_disc >0 order by yong_money desc limit {$offset},{$per_page}";
  540. **/
  541. $list = M()->query($sql);
  542. foreach ($list as $k => $v) {
  543. $v['image']=C('SITE_URL'). resize($v['image'], C('spike_thumb_width'), C('spike_thumb_height'));
  544. $pin_yong_money = round( $v['pin_yong_money'] /100 , 2);
  545. $dan_yong_money = round( $v['dan_yong_money'] /100 , 2);
  546. if( $pin_yong_money > $dan_yong_money )
  547. {
  548. $v['yong_money'] = $pin_yong_money;
  549. $v['price'] = $v['pin_price'];
  550. } else {
  551. $v['yong_money'] = $dan_yong_money;
  552. $v['price'] = $v['danprice'];
  553. }
  554. //"danprice":"0.04","pin_price":"0.01",
  555. $list[$k] = $v;
  556. }
  557. if( empty($list) )
  558. {
  559. echo json_encode( array('code' => 1) );
  560. die();
  561. } else {
  562. echo json_encode( array('code' =>0, 'data' => $list) );
  563. die();
  564. }
  565. /**
  566. SELECT a.goods_id, a.commiss_one_dan_disc, b.commiss_one_pin_disc
  567. FROM `oscshop_goods` as a left join oscshop_pin_goods as b on a.goods_id = b.goods_id WHERE a.commiss_one_dan_disc >0 and a.status = 1 and a.quantity >0 order by a.goods_id desc
  568. **/
  569. }
  570. }