MultiPkMall.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. <?php
  2. namespace app\api\controller;
  3. use think\cache\driver\Redis;
  4. use think\Db;
  5. use EasyWeChat\Factory;
  6. use think\Exception;
  7. use think\Session;
  8. /**
  9. * @title 多人pk商城
  10. * @controller MultiPkMall
  11. * @group base
  12. */
  13. class MultiPkMall extends Base
  14. {
  15. public $crit_rate = 0;//暴击率
  16. public function initialize()
  17. {
  18. parent::initialize();
  19. //parent::check_login();
  20. }
  21. /**
  22. * @title 立即购买
  23. * @desc 立即购买
  24. * @author qc
  25. * @url /api/Multi_pk_mall/payOrderImmediately
  26. * @method POST
  27. * @header name:Authorization require:1 desc:Token
  28. * @param name:goods_id type:int require:1 default:-- desc:商品id
  29. * @param name:place type:int require:1 default:0 desc:位置(1红1,2红2,3橙1,4橙2)
  30. * @param name:pay_type type:int require:1 default:1 desc:支付方式(1明信片,2余额,3混合)
  31. * @return name:order_id type:int require:0 default:0 desc:成功时返回订单id
  32. * @return name:is_crit type:int require:0 default:0 desc:是否暴击
  33. * @return name:can_pk type:array require:0 default:0 desc:可以pk的记录
  34. * @return name:can_pk.create_at type:string require:0 default:'' desc:时间
  35. * @return name:can_pk.case_name type:string require:0 default:'' desc:抽中商品
  36. * @return name:can_pk.case_cover type:string require:0 default:'' desc:抽中商品封面
  37. * @return name:can_pk.goods_title type:string require:0 default:'' desc:标题
  38. * @return name:can_pk.color type:string require:0 default:'' desc:颜色(0黑色,1红色,2金色)
  39. * @return name:can_pk.crystal type:string require:0 default:'' desc:明信片
  40. * @return name:pk_log type:array require:0 default:0 desc:pk胜利记录
  41. * @return name:pk_log.win_data type:array require:0 default:0 desc:详情
  42. * @return name:pk_log.win_data.case_name type:string default:-- desc:奖励名称
  43. * @return name:pk_log.win_data.case_cover type:string default:-- desc:封面
  44. * @return name:pk_log.win_data.crystal type:string default:-- desc:明信片价值
  45. * @return name:pk_log.win_data.code type:int default:-- desc:编码
  46. * @return name:pk_log.win_data.user_name type:int default:-- desc:会员名称
  47. * @return name:pk_log.win_data.headimg type:int default:-- desc:会员头像
  48. * @return name:pk_log.lost_data type:array require:0 default:0 desc:失败详情
  49. * @return name:pk_log.lost_data.case_name type:string default:-- desc:奖励名称
  50. * @return name:pk_log.lost_data.case_cover type:string default:-- desc:封面
  51. * @return name:pk_log.lost_data.crystal type:string default:-- desc:明信片价值
  52. * @return name:pk_log.lost_data.code type:int default:-- desc:编码
  53. * @return name:pk_log.lost_data.user_name type:int default:-- desc:会员名称
  54. * @return name:pk_log.lost_data.headimg type:int default:-- desc:会员头像
  55. *
  56. */
  57. public function payOrderImmediately()
  58. {
  59. Db::startTrans();
  60. $msg= '';$com=true;
  61. try{
  62. $goods_id = input("post.goods_id");
  63. $num = input("post.num",1);
  64. $place = input("post.place");
  65. $pay_type = input("post.pay_type",1);
  66. $place_arr = [1,2,3,4];
  67. if(!in_array($place,$place_arr)) throw new Exception('请选择位置!');
  68. $goods_info = Db::table('pk_goods')->where(['id'=>$goods_id,'status'=>1,'is_deleted'=>0])->find();
  69. $price_total = bcmul($goods_info['goods_price'],$num,2);
  70. if(empty($goods_info)) throw new Exception('商品已下架');
  71. // if(!$goods_info['end_time'] || strtotime($goods_info['end_time']) < time()) throw new Exception('商品售卖时间已结束');
  72. if( $goods_info['stock'] < $num) throw new Exception('商品库存不足无法进行pk');
  73. if($price_total <= 0) throw new Exception('金额有误');
  74. $user_info = Db::table('store_member')->find($this->uid);
  75. if($pay_type == 1 && $user_info['crystal'] < $price_total) throw new Exception('明信片不足!');
  76. if($pay_type == 2 && $user_info['crystal_cash'] < $price_total) throw new Exception('余额不足!');
  77. if($pay_type == 3 && $price_total > 0 && bcadd($user_info['crystal'],$user_info['crystal_cash'],2) < $price_total) throw new Exception('余额不足!');
  78. // 验证待pk位置,最多3个
  79. $check_num = Db::table('pk_draw')->where(['goods_id'=>$goods_id,'pk_status'=>0,'full_num'=>4,'place'=>$place])->count();
  80. if($check_num >= 3 ) throw new Exception('该位置已满!');
  81. // pk 防截胡
  82. $limit_fifty = Db::table('pk_draw')->field('id,user_id')->where('goods_id',$goods_id)->where('full_num',4)->limit(0,50)->select();
  83. $buy_num = 0;
  84. if($goods_info['base_stock'] - $goods_info['stock'] > 50){
  85. foreach ($limit_fifty as $fv){
  86. if($fv['user_id'] == $this->uid) $buy_num++;
  87. }
  88. if($buy_num < 5 ) throw new Exception('购物买权限不足!');
  89. }else if($goods_info['base_stock']- $goods_info['stock'] - $num > 50) {
  90. $num = $goods_info['base_stock']- $goods_info['stock'] - $num - 50 ;
  91. foreach ($limit_fifty as $fv){
  92. if($fv['user_id'] == $this->uid) $buy_num++;
  93. }
  94. if((50 - count($limit_fifty) + $buy_num) < 5 ) throw new Exception('试试少买几个~!!~');
  95. }
  96. // pk 防截胡end
  97. // 订单数据 && 生成订单
  98. $order_info =[
  99. 'uid' =>$this->uid,
  100. 'order_no' => get_order_sn(),
  101. 'price_total' => $price_total,
  102. 'goods_num' => $num,
  103. 'goods_id' => $goods_id,
  104. 'goods_cover' => $goods_info['cover'],
  105. 'goods_name' => $goods_info['name'],
  106. 'create_at' => date('Y-m-d H:i:s'),
  107. 'pay_time' => date('Y-m-d H:i:s'),
  108. 'pay_type' => $pay_type,
  109. 'pay_state' => 1,
  110. 'status' => 1,
  111. 'full_num' => 4,
  112. 'pay_no' => get_order_sn()
  113. ];
  114. Db::table('pk_order')->insert($order_info);
  115. $order_id = Db::getLastInsID();
  116. $order_info['id'] = $order_id;
  117. // 扣除余额
  118. if($order_info['price_total'] > 0){
  119. // 扣除余额
  120. if($pay_type == 1) {
  121. Db::table('store_member')->where(['id'=>$this->uid])->update([
  122. 'crystal'=>bcsub($user_info['crystal'],$order_info['price_total'],2),
  123. ]);
  124. crystal_log($this->uid,$order_info['price_total'],'明信片支付',6);
  125. }else if($pay_type == 2){
  126. Db::table('store_member')->where(['id'=>$this->uid])->update([
  127. 'crystal_cash'=>bcsub($user_info['crystal_cash'],$order_info['price_total'],2),
  128. ]);
  129. balance_log($this->uid,$order_info['price_total'],'余额支付',6);
  130. }else{
  131. $user_up = [];
  132. if($user_info['crystal_cash'] >= $order_info['price_total'] ){
  133. $user_up['crystal_cash'] = bcsub($user_info['crystal_cash'],$order_info['price_total'],2);
  134. balance_log($this->uid,$order_info['price_total'],'余额支付',6);
  135. }else{
  136. $user_up['crystal_cash'] = 0;
  137. $user_up['crystal'] = bcsub( $user_info['crystal_cash'] + $user_info['crystal'],$order_info['price_total'],2);
  138. crystal_log($this->uid,$user_info['crystal'] - $user_up['crystal'] ,'明信片支付',6);
  139. }
  140. Db::table('store_member')->where(['id'=>$this->uid])->update($user_up);
  141. }
  142. }
  143. // 扣除余额end
  144. $magic_day = intval(sysconf('magic_days'));// 获取设置天数
  145. $base_award = json_decode($goods_info['base_award'],true);
  146. // 抽奖设置
  147. $goods_spec = json_decode($goods_info['spec'],true);
  148. $draw_data = point_lottery($goods_spec,'store_num',1);
  149. // 抽奖详情
  150. $draw_info = [];
  151. foreach ($draw_data as $dk=>$dv) {
  152. $goods_spec[$dk]['store_num'] -= $dv;
  153. $draw_info = [
  154. 'user_id' => $this->uid,
  155. 'create_at' => date('Y-m-d H:i:s'),
  156. 'goods_id' => $goods_id,
  157. 'order_id' => $order_id,
  158. 'case_name' => $goods_spec[$dk]['award_name'],
  159. 'goods_title'=> $goods_spec[$dk]['award_title'],
  160. 'case_cover'=> $goods_spec[$dk]['spec_img'],
  161. 'num' => 1,
  162. 'spec_key' => $dk,
  163. 'crystal' => $goods_spec[$dk]['crystal'],
  164. 'code' => $goods_spec[$dk]['code'],
  165. 'color' => $goods_spec[$dk]['color'],
  166. 'place' => $place,
  167. 'full_num' => $goods_info['full_num'],
  168. ];
  169. }
  170. Db::table('pk_draw')->insert($draw_info);
  171. $draw_info['id'] = Db::getLastInsID();
  172. // 位置查询
  173. $full_draw = [];
  174. foreach ($place_arr as $plv)
  175. {
  176. if($place != $plv) {
  177. $ck_draw = Db::table('pk_draw')
  178. ->where(['goods_id'=>$goods_id,'pk_status'=>0,'full_num'=>4,'place'=>$plv])
  179. ->limit(0,1)
  180. ->order('id asc')
  181. ->select();
  182. if(!empty($ck_draw)) $full_draw[] = $ck_draw[0];
  183. }else{
  184. $full_draw[] = $draw_info;
  185. }
  186. }
  187. $goods_update = [];
  188. // 能pk
  189. if(count($full_draw) == 4) {
  190. array_multisort(array_column($full_draw,'place'), SORT_ASC, $full_draw);// 按位置升序排序
  191. $red_team = [$full_draw[0], $full_draw[1]];// 红队id
  192. $orange_team = [$full_draw[3], $full_draw[4]];// 橙队id
  193. // 抽中金额、编码 排序
  194. $rank_draw = Db::table('pk_draw')
  195. ->where('id','in',array_column($full_draw,'id'))
  196. ->order('crystal desc ,code desc , id desc')
  197. ->select();
  198. $red_win = 1;// 是否是红队赢
  199. // 红队赢
  200. if(in_array($rank_draw[0]['id'],array_column($red_team,'id'))) {
  201. // 红1最大
  202. if($rank_draw[0]['id'] == $red_team[0]['id']){
  203. $win_magic = [
  204. $this->getWinData($red_team,0,0,$goods_id,$rank_draw,$magic_day),
  205. $this->getWinData($red_team,1,1,$goods_id,$rank_draw,$magic_day),
  206. ];
  207. }else{
  208. $win_magic = [
  209. $this->getWinData($red_team,0,1,$goods_id,$rank_draw,$magic_day),
  210. $this->getWinData($red_team,1,0,$goods_id,$rank_draw,$magic_day),
  211. ];
  212. }
  213. Db::table('magic_case')->insertAll($win_magic);
  214. // pk 输了是否有安慰奖
  215. if($base_award['base_crystal'] > 0 && $base_award['base_goods']) {
  216. $lose_case = [];
  217. array_map(function ($val)use(&$lose_case,$goods_id,$magic_day,$base_award){
  218. $lose_case[] = [
  219. 'order_id' => $val['order_id'],
  220. 'goods_id' => $goods_id,
  221. 'user_id' => $val['user_id'],
  222. 'create_at' => date('Y-m-d H:i:s'),
  223. 'num' => 1,
  224. 'base_num' => 1,
  225. 'source' => 0,
  226. 'crystal' => $base_award['base_crystal'],
  227. 'case_name' => $base_award['base_goods'],
  228. 'case_cover' => $base_award['base_cover'],
  229. 'past_at' => date('Y-m-d H:i:s',strtotime("+$magic_day days")),
  230. 'past_int' => strtotime("+$magic_day days"),
  231. 'draw_id' => $val['id'],
  232. 'from' => 3,
  233. ];
  234. },$orange_team);
  235. Db::table('magic_case')->insertAll($lose_case);
  236. }else{
  237. $lose_case=[
  238. ['user_id'=>$orange_team[0]['user_id'],'order_id'=>$orange_team[0]['order_id'],'case_name'=>''],
  239. ['user_id'=>$orange_team[1]['user_id'],'order_id'=>$orange_team[1]['order_id'],'case_name'=>''],
  240. ];
  241. }
  242. }else{
  243. // 橙队获胜
  244. $red_win = 0;
  245. // 橙1最大
  246. if($rank_draw[0]['id'] == $orange_team[0]['id']){
  247. $win_magic = [
  248. $this->getWinData($orange_team,0,0,$goods_id,$rank_draw,$magic_day),
  249. $this->getWinData($orange_team,1,1,$goods_id,$rank_draw,$magic_day),
  250. ];
  251. }else{
  252. $win_magic = [
  253. $this->getWinData($orange_team,0,1,$goods_id,$rank_draw,$magic_day),
  254. $this->getWinData($orange_team,1,0,$goods_id,$rank_draw,$magic_day),
  255. ];
  256. }
  257. Db::table('magic_case')->insertAll($win_magic);
  258. // pk 输了是否有安慰奖
  259. if($base_award['base_crystal'] > 0 && $base_award['base_goods']) {
  260. $lose_case = [];
  261. array_map(function ($val)use(&$lose_case,$goods_id,$magic_day,$base_award){
  262. $lose_case[] = [
  263. 'order_id' => $val['order_id'],
  264. 'goods_id' => $goods_id,
  265. 'user_id' => $val['user_id'],
  266. 'create_at' => date('Y-m-d H:i:s'),
  267. 'num' => 1,
  268. 'base_num' => 1,
  269. 'source' => 0,
  270. 'crystal' => $base_award['base_crystal'],
  271. 'case_name' => $base_award['base_goods'],
  272. 'case_cover' => $base_award['base_cover'],
  273. 'past_at' => date('Y-m-d H:i:s',strtotime("+$magic_day days")),
  274. 'past_int' => strtotime("+$magic_day days"),
  275. 'draw_id' => $val['id'],
  276. 'from' => 3,
  277. ];
  278. },$red_team);
  279. Db::table('magic_case')->insertAll($lose_case);
  280. }else{
  281. $lose_case=[
  282. ['user_id'=>$red_team[0]['user_id'],'order_id'=>$red_team[0]['order_id'],'case_name'=>''],
  283. ['user_id'=>$red_team[1]['user_id'],'order_id'=>$red_team[1]['order_id'],'case_name'=>''],
  284. ];
  285. }
  286. }
  287. $multi_info = [
  288. 'create_at' => date('Y-m-d H:i:s'),
  289. 'goods_id' => $goods_id,
  290. 'red_team' => $red_win ? json_encode($win_magic):json_encode($lose_case),
  291. 'orange_team' => $red_win ? json_encode($lose_case):json_encode($win_magic),
  292. 'base_data' => json_encode($base_award),
  293. 'red_win' => $red_win,
  294. 'win_order1' => $win_magic[0]['order_id'],
  295. 'win_order2' => $win_magic[1]['order_id'],
  296. 'win_user1' => $win_magic[0]['user_id'],
  297. 'win_user2' => $win_magic[2]['user_id'],
  298. 'lose_order1' => $lose_case[0]['order_id'],
  299. 'lose_order2' => $lose_case[1]['order_id'],
  300. 'lose_user1' => $lose_case[0]['user_id'],
  301. 'lose_user2' => $lose_case[2]['user_id'],
  302. 'full_draw' => json_encode($full_draw),
  303. ];
  304. Db::table('pk_multi_info')->insert($multi_info);
  305. // 更新PK抽奖记录
  306. Db::table('pk_draw')->where('id','in',[$rank_draw[0]['id'],$rank_draw[1]['id']])->update(['pk_status'=>$red_win?2:1]);
  307. Db::table('pk_draw')->where('id','in',[$rank_draw[2]['id'],$rank_draw[3]['id']])->update(['pk_status'=>$red_win?1:2]);
  308. foreach ($rank_draw as $fk=>$fv) {
  309. if(in_array($fk,[0,1])) continue;
  310. // 恢复库存
  311. $goods_spec[$fv['spec_key']]['store_num']++;
  312. $goods_info['stock']++;
  313. }
  314. $goods_update['pk_num'] = $goods_info['pk_num'] + 1;
  315. }
  316. // 更新库存 && 规格详情
  317. $goods_update['spec'] = json_encode($goods_spec);
  318. $goods_update['stock'] = $goods_info['stock'] - 1;
  319. Db::table('pk_goods')->where('id',$goods_info['id'])->update($goods_update);
  320. Db::commit();
  321. }catch (\Exception $e){
  322. Db::rollback();
  323. $com=false;
  324. $msg = $e->getMessage();
  325. }
  326. if($com) {
  327. $can_pk = Db::table('pk_draw')->where(['order_id'=>$order_id,'pk_status'=>0,'full_num'=>4])->select();//可以PK数据
  328. $pk_log = Db::table('pk_info')->where(['lose_order|win_order'=>$order_id])->select();
  329. foreach ($pk_log as &$lv){
  330. $lv['base_data'] = json_decode($lv['base_data'],true);
  331. $win_data = json_decode($lv['win_data'],true);
  332. $lose_data = json_decode($lv['lose_data'],true);
  333. $win_user = Db::table('store_member')->field('headimg,name')->where('id',$lv['win_user'])->find();
  334. $lose_user = Db::table('store_member')->field('headimg,name')->where('id',$lv['lose_user'])->find();
  335. $win_data['headimg'] =$win_user['headimg'];
  336. $win_data['user_name'] =$win_user['name'];
  337. $lose_data['headimg'] =$lose_user['headimg'];
  338. $lose_data['user_name'] =$lose_user['name'];
  339. $lv['win_data'] = $win_data;
  340. $lv['lose_data'] = $lose_data;
  341. }
  342. $this->success('ok',['order_id'=>$order_id ? : 0,'can_pk'=>$can_pk,'pk_log'=>$pk_log]);
  343. }else{
  344. $this->error($msg);
  345. }
  346. }
  347. // 获取pk胜利数据
  348. public function getWinData($team,$win_key,$award_key,$goods_id,$rank_draw,$magic_day,$place = 0)
  349. {
  350. return [
  351. 'order_id' => $team[$win_key]['order_id'],
  352. 'goods_id' => $goods_id,
  353. 'user_id' => $team[$win_key]['user_id'],
  354. 'create_at' => date('Y-m-d H:i:s'),
  355. 'num' => 1,
  356. 'base_num' => 1,
  357. 'source' => 0,
  358. 'crystal' => $rank_draw[$award_key]['crystal'],
  359. 'case_name' => $rank_draw[$award_key]['case_name'],
  360. 'case_cover'=> $rank_draw[$award_key]['case_cover'],
  361. 'past_at' => date('Y-m-d H:i:s',strtotime("+$magic_day days")),
  362. 'past_int' => strtotime("+$magic_day days"),
  363. 'color' => $rank_draw[$award_key]['color'],
  364. 'draw_id' => $rank_draw[$award_key]['id'],
  365. 'from' => 3,
  366. 'place' => $place
  367. ];
  368. }
  369. /**
  370. * @title 取消PK
  371. * @desc 取消PK
  372. * @author qc
  373. * @url /api/Multi_pk_mall/cancelPk
  374. * @method POST
  375. * @header name:Authorization require:1 desc:Token
  376. * @param name:goods_id type:int require:1 default:-- desc:商品id
  377. */
  378. public function cancelPk()
  379. {
  380. $goods_id = input('post.goods_id');
  381. Db::startTrans();
  382. $msg = '取消成功!';
  383. try {
  384. $cancel_data = Db::table('pk_draw')
  385. ->where(['user_id'=>$this->uid,'goods_id'=>$goods_id,'pk_status'=>0,'full_num'=>4])
  386. ->select();
  387. if(empty($cancel_data)) throw new Exception('PK已完成');
  388. $goods_info = Db::table('pk_goods')->find($goods_id);
  389. $goods_spec = json_decode($goods_info['spec'],true);
  390. foreach ($cancel_data as $cv) {
  391. $goods_spec[$cv['spec_key']]['store_num']++;
  392. $order_info = Db::table('pk_order')->field('id,pay_type')->find($cv['order_id']);
  393. $user_info = Db::table('store_member')->find($this->uid);
  394. if($order_info['pay_type'] == 1){
  395. Db::table('store_member')->where('id',$this->uid)->update(['crystal'=>$user_info['crystal']+$goods_info['goods_price']]);
  396. crystal_log($this->uid,$goods_info['goods_price'],'PK订单取消',9,$cv['order_id']);
  397. }else{
  398. Db::table('store_member')->where('id',$this->uid)->update(['crystal_cash'=>$user_info['crystal_cash']+$goods_info['goods_price']]);
  399. balance_log($this->uid,$goods_info['goods_price'],'PK订单取消',9,$cv['order_id']);
  400. }
  401. }
  402. // 恢复商品库存
  403. Db::table('pk_goods')->where('id',$goods_id)->update(['spec'=>json_encode($goods_spec),'stock'=>$goods_info['stock']+count($cancel_data)]);
  404. // 取消记录
  405. Db::table('pk_draw')->where(['user_id'=>$this->uid,'goods_id'=>$goods_id,'pk_status'=>0,'full_num'=>4])->update(['pk_status'=>3]);
  406. Db::commit();
  407. }catch (\Exception $e){
  408. $msg = $e->getMessage();
  409. Db::rollback();
  410. }
  411. $this->success($msg);
  412. }
  413. /**
  414. * @title 获取已pk记录
  415. * @desc 获取已pk记录
  416. * @author qc
  417. * @url /api/Multi_pk_mall/getAllPkLog
  418. * @method GET
  419. * @header name:Authorization require:1 desc:Token
  420. * @param name:page type:int default:1 desc:页数
  421. * @param name:page_num type:int : default:20 desc:每页数
  422. * @param name:goods_id type:string require:1 default:-- desc:商品id
  423. * @param name:is_win type:string require:1 default:-- desc:pk输赢(0输1赢)
  424. * @return name:draw_info type:array default:-- desc:抽中数据
  425. * @return name:draw_info.case_name type:string default:-- desc:奖励名称
  426. * @return name:draw_info.case_cover type:string default:-- desc:封面
  427. * @return name:draw_info.crystal type:string default:-- desc:明信片价值
  428. * @return name:draw_info.code type:int default:-- desc:编码
  429. * @return name:draw_info.user_name type:int default:-- desc:会员名称
  430. * @return name:draw_info.headimg type:int default:-- desc:会员头像
  431. * @return name:win_user type:int default:-- desc:pk胜利会员id
  432. * @return name:lose_user type:int default:-- desc:pk失败会员id
  433. * @return name:win_order type:int default:-- desc:pk胜利会员订单id
  434. * @return name:lose_order type:int default:-- desc:pk失败会员订单id
  435. * @return name:goods_status type:int default:-- desc:商品上下架状态(0下架1上架)
  436. * @return name:goods_deleted type:int default:-- desc:商品删除状态(0未删除1删除)
  437. * @return name:goods_name type:int default:-- desc:商品名称
  438. */
  439. public function getAllPkLog()
  440. {
  441. $user_info = Db::table('store_member')->find($this->uid);
  442. $list = Db::table('pk_info')->alias('p')
  443. ->field('p.id,p.goods_id,p.create_at,p.win_data,p.lose_data,p.win_user,p.lose_user,g.status as goods_status,g.is_deleted as goods_deleted,g.name as goods_name')
  444. ->where('win_user|lose_user',$this->uid)
  445. ->join('pk_goods g','g.id = p.goods_id','LEFT')
  446. ->order('p.id desc ')
  447. ->limit($this->off_set,$this->page_num)
  448. ->select();
  449. foreach ($list as &$lv) {
  450. $lv['is_win'] = $lv['win_user'] == $this->uid ? 1:0;
  451. $win_data = json_decode($lv['win_data'],true);
  452. $lose_data = json_decode($lv['lose_data'],true);
  453. $lv['draw_info'] = $lv['win_user'] == $this->uid ?$win_data:$lose_data;
  454. $lv['user_name'] = $user_info['name'];
  455. $lv['headimg'] = $user_info['headimg'];
  456. $lv['win_data'] =$win_data;
  457. $lv['lose_data'] =$lose_data;
  458. }
  459. $this->success('ok',['list'=>$list]);
  460. }
  461. /**
  462. * @title 获取待pk记录(pk商品)
  463. * @desc 获取待pk记录(pk商品)
  464. * @author qc
  465. * @url /api/Multi_pk_mall/getCanPkLog
  466. * @method GET
  467. * @header name:Authorization require:1 desc:Token
  468. * @return name:list type:array default:-- desc:待PK记录
  469. * @return name:list.headimg type:string default:-- desc:会员头像
  470. * @return name:list.user_name type:string default:-- desc:会员名称
  471. * @return name:list.create_at type:string default:-- desc:时间
  472. */
  473. public function getCanPkLog()
  474. {
  475. $user_info = Db::table('store_member')->find($this->uid);
  476. $list = Db::table('pk_draw')->alias('p')
  477. ->field('p.id,p.user_id,p.goods_id,p.create_at,g.status,g.name as goods_name')
  478. ->where(['user_id'=>$this->uid,'pk_status'=>0,'full_num'=>4])
  479. ->join('pk_goods g','g.id = p.goods_id','LEFT')
  480. ->order('p.id desc')
  481. ->select();
  482. foreach ($list as &$lv){
  483. $lv['headimg'] = $user_info['headimg'];
  484. $lv['user_name'] = $user_info['name'];
  485. }
  486. $this->success('ok',['list'=>$list]);
  487. }
  488. }