Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
ylc.llewan.com
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
llewan
ylc.llewan.com
Commits
eb35367f
Commit
eb35367f
authored
Sep 27, 2018
by
734642908@qq.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加商品兑换接口
parent
24e62b31
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
309 additions
and
0 deletions
+309
-0
ShopController.class.php
Application/Home/Controller/ShopController.class.php
+82
-0
ShopModel.class.php
Application/Home/Model/ShopModel.class.php
+227
-0
No files found.
Application/Home/Controller/ShopController.class.php
View file @
eb35367f
...
@@ -45,6 +45,87 @@ class ShopController extends BaseController
...
@@ -45,6 +45,87 @@ class ShopController extends BaseController
echo
$this
->
formatRes
(
$result
);
echo
$this
->
formatRes
(
$result
);
}
}
//用户商品列表
public
function
userGoods
()
{
$token
=
decryptToken
(
I
(
'token'
));
//获取数量(分页)
$size
=
I
(
'size'
,
10
);
$page
=
I
(
'page'
,
1
);
$skip
=
$size
*
(
$page
-
1
);
if
(
$token
==
false
)
{
$result
=
array
(
'c'
=>
2
,
'msg'
=>
'token不正确'
);
echo
$this
->
formatRes
(
$result
);
exit
;
}
$whereArr
=
array
(
'status'
=>
1
);
if
(
$isShow
==
1
)
{
$whereArr
[
'is_show'
]
=
$isShow
;
}
$field
=
'sysid as order_id,goods_id,name,icon,gold,status,create_time'
;
$orderArr
=
M
(
"yl_goods_order"
,
""
,
C
(
"LEWAN_HEZI"
))
->
where
(
array
(
'uid'
=>
$token
[
'uid'
]))
->
field
(
$field
)
->
limit
(
$skip
,
$size
)
->
order
(
'create_time desc'
)
->
select
();
if
(
!
empty
(
$orderArr
))
{
$result
=
array
(
'c'
=>
1
,
'msg'
=>
'获取成功'
,
'd'
=>
array
(
'list'
=>
$orderArr
)
);
}
else
{
$result
=
array
(
'c'
=>
2
,
'msg'
=>
'暂无数据'
);
}
echo
$this
->
formatRes
(
$result
);
}
//商品兑换
public
function
goodsChange
()
{
$token
=
decryptToken
(
I
(
'token'
));
$goodsId
=
I
(
'goods_id'
);
$changeWay
=
I
(
'change_way'
);
if
(
$token
==
false
)
{
$result
=
array
(
'c'
=>
2
,
'msg'
=>
'token不正确'
);
echo
$this
->
formatRes
(
$result
);
exit
;
}
else
if
(
empty
(
$goodsId
))
{
$result
=
array
(
'c'
=>
2
,
'msg'
=>
'goods_id参数不存在'
);
echo
$this
->
formatRes
(
$result
);
exit
;
}
else
if
(
empty
(
$changeWay
))
{
$result
=
array
(
'c'
=>
2
,
'msg'
=>
'change_way参数不存在'
);
echo
$this
->
formatRes
(
$result
);
exit
;
}
$model
=
new
\Home\Model\ShopModel
();
$result
=
$model
->
goodsChange
(
$token
[
'uid'
],
$goodsId
,
$changeWay
);
echo
$this
->
formatRes
(
$result
);
}
}
}
?>
?>
\ No newline at end of file
Application/Home/Model/ShopModel.class.php
0 → 100644
View file @
eb35367f
<?php
namespace
Home\Model
;
class
ShopModel
extends
BaseModel
{
function
goodsChange
(
$uid
,
$goodsId
,
$changeWay
)
{
//查询商品信息
$goodsArr
=
M
(
"yl_goods"
,
""
,
$this
->
__lewan_hezi
)
->
where
(
array
(
'status'
=>
1
,
'sysid'
=>
$goodsId
))
->
find
();
if
(
empty
(
$goodsArr
))
{
return
$result
=
array
(
'c'
=>
2
,
'msg'
=>
'goods_id参数错误'
);
}
//判断兑换方式
if
(
$changeWay
==
1
)
{
//直接金币兑换
$memberModel
=
M
(
"game_member"
,
""
,
$this
->
__lewan_hezi
);
$memberModel
->
startTrans
();
try
{
//扣除用户金币
$re1
=
$memberModel
->
where
(
array
(
'uid'
=>
$uid
))
->
setDec
(
'gold'
,
$goodsArr
[
'initial_price'
]);
//扣除商品库存
$re2
=
M
(
"yl_goods"
,
""
,
$this
->
__lewan_hezi
)
->
where
(
array
(
'sysid'
=>
$goodsId
))
->
setDec
(
'stock'
,
1
);
}
catch
(
\Exception
$e
)
{
if
(
!
$re1
)
{
return
$result
=
array
(
'c'
=>
2
,
'msg'
=>
'兑换失败,玩币不足'
);
}
if
(
!
$re2
)
{
return
$result
=
array
(
'c'
=>
2
,
'msg'
=>
'兑换失败,库存不足'
);
}
}
//生成订单ID
$continue
=
true
;
while
(
$continue
)
{
$orderId
=
mt_rand
(
1000
,
9999
)
.
mt_rand
(
1000
,
9999
)
.
mt_rand
(
1000
,
9999
);
$num
=
M
(
"yl_goods_order"
,
""
,
$this
->
__lewan_hezi
)
->
where
(
array
(
'sysid'
=>
$orderId
))
->
count
();
if
(
$num
<
1
)
{
$continue
=
false
;
}
}
//记录商品订单
$orderArr
=
array
(
'sysid'
=>
$orderId
,
'uid'
=>
$uid
,
'goods_id'
=>
$goodsId
,
'name'
=>
$goodsArr
[
'name'
]
,
'icon'
=>
$goodsArr
[
'icon'
]
,
'gold'
=>
$goodsArr
[
'initial_price'
]
,
'status'
=>
2
,
'create_time'
=>
date
(
'Y-m-d H:i:s'
)
,
'pay_time'
=>
date
(
'Y-m-d H:i:s'
)
,
'game_code'
=>
'ylc'
,
'change_way'
=>
1
,
'goods_type'
=>
$goodsArr
[
'type'
]
);
$re3
=
M
(
"yl_goods_order"
,
""
,
$this
->
__lewan_hezi
)
->
add
(
$orderArr
);
//记录用户金币操作
$goldArr
=
array
(
'uid'
=>
$uid
,
'handle'
=>
'reduce'
,
'gold_num'
=>
$goodsArr
[
'initial_price'
]
,
'add_time'
=>
date
(
'Y-m-d H:i:s'
)
,
'way'
=>
'goods_change'
,
'game_code'
=>
'ylc'
);
$re4
=
M
(
"game_member_gold"
,
""
,
$this
->
__lewan_hezi
)
->
add
(
$goldArr
);
if
(
$re3
&&
$re4
)
{
$memberModel
->
commit
();
$result
=
array
(
'c'
=>
1
,
'msg'
=>
'兑换成功'
);
}
else
{
$result
=
array
(
'c'
=>
2
,
'msg'
=>
'兑换失败'
);
}
}
return
$result
;
}
function
label
(
$gameId
=
array
())
{
$model
=
M
(
"yl_game_label"
,
""
,
$this
->
__lewan_hezi
);
if
(
!
empty
(
$gameId
))
{
$where
=
array
(
'yl_game_label_list.r_game'
=>
array
(
'in'
,
$gameId
));
$model
=
$model
->
join
(
'left join yl_game_label_list on yl_game_label.sysid=yl_game_label_list.r_label'
);
$list
=
$model
->
where
(
$where
)
->
field
(
'yl_game_label_list.r_label,yl_game_label_list.r_game,yl_game_label.name'
)
->
select
();
}
else
{
$list
=
$model
->
field
(
'sysid,name'
)
->
select
();
}
return
$list
;
}
//游戏点击记录
function
clickCount
(
$uid
,
$gid
)
{
$result
=
Array
();
$taskList
=
C
(
'taskList'
);
$memberModel
=
M
(
"yl_member_game"
,
""
,
$this
->
__lewan_hezi
);
$memberModel
->
startTrans
();
//记录用户游戏列表数据
$memberWhere
=
array
(
'uid'
=>
$uid
,
'r_game'
=>
$gid
);
$gameNum
=
$memberModel
->
where
(
$memberWhere
)
->
count
();
if
(
$gameNum
>
0
)
{
$re1
=
$memberModel
->
where
(
$memberWhere
)
->
setInc
(
'num'
,
1
);
}
else
{
$memberkAdd
=
array
(
'uid'
=>
$uid
,
'r_game'
=>
$gid
,
'create_time'
=>
date
(
'Y-m-d H:i:s'
)
);
$re1
=
$memberModel
->
add
(
$memberkAdd
);
}
//游乐场游戏点击数据表
$clickArr
=
array
(
'uid'
=>
$uid
,
'r_game'
=>
$gid
,
'create_time'
=>
date
(
'Y-m-d H:i:s'
)
);
$re2
=
M
(
"yl_game_onclick_log"
,
""
,
$this
->
__lewan_hezi
)
->
add
(
$clickArr
);
//游乐场游戏点击数更新
$re3
=
M
(
"yl_game"
,
""
,
$this
->
__lewan_hezi
)
->
where
(
array
(
'sysid'
=>
$gid
))
->
setInc
(
'true_num'
,
1
);
if
(
$re1
&&
$re2
&&
$re3
)
{
$memberModel
->
commit
();
/*------------------------------------玩游戏任务记录------------------------------------*/
$taskModel
=
M
(
"yl_game_task"
,
""
,
$this
->
__lewan_hezi
);
// $taskEnName = $taskList[0]['en_name'];
// $taskChName = $taskList[0]['ch_name'];
//获取用户今天做任务数据
// $sql = "select * from ".get_table("game_global_task")." where uid=$uid and en_name='$taskEnName' and add_time > '".date('Y-m-d')."' order by add_time desc";
// $result = $GLOBALS["conn"]->Query($sql);
// $taskArr = $GLOBALS["conn"]->getOne($result);
$whereArr
=
array
(
'uid'
=>
$uid
,
'type'
=>
'click_game'
,
'game_code'
=>
'ylc'
,
'add_time'
=>
array
(
'gt'
,
date
(
'Y-m-d'
))
);
$taskArr
=
$taskModel
->
where
(
$whereArr
)
->
find
();
if
(
!
empty
(
$taskArr
))
{
//更新今日任务进度
// $tupdateArr = array(
// 'schedule'=>'schedule+1'
// );
$receiveArr
=
json_decode
(
$taskArr
[
'receive_info'
],
true
);
$taskModel
->
where
(
$whereArr
)
->
setInc
(
'schedule'
,
1
);
if
(
$taskArr
[
'schedule'
]
>=
2
&&
$receiveArr
[
'click_game3'
][
'status'
]
==
1
)
{
$receiveArr
[
'click_game3'
][
'status'
]
=
2
;
$taskModel
->
where
(
$whereArr
)
->
save
(
array
(
'receive_info'
=>
json_encode
(
$receiveArr
)));
}
if
(
$taskArr
[
'schedule'
]
>=
9
&&
$receiveArr
[
'click_game10'
][
'status'
]
==
1
)
{
$receiveArr
[
'click_game10'
][
'status'
]
=
2
;
$taskModel
->
where
(
$whereArr
)
->
save
(
array
(
'receive_info'
=>
json_encode
(
$receiveArr
)));
}
// $twhere =" and uid=$uid and en_name='$taskEnName' and add_time > '".date('Y-m-d')."'";
// update_record($GLOBALS["conn"],'game_global_task',$tupdateArr,'',$twhere);
}
else
{
$receiveArr
=
array
(
'click_game1'
=>
array
(
'status'
=>
2
)
,
'click_game3'
=>
array
(
'status'
=>
1
)
,
'click_game10'
=>
array
(
'status'
=>
1
)
);
//添加今日任务记录
$taddArr
=
array
(
"uid"
=>
$uid
,
"en_name"
=>
'click_game'
,
"ch_name"
=>
'点击游戏'
,
'add_time'
=>
date
(
'Y-m-d H:i:s'
)
,
'add_ip'
=>
$ip
,
'type'
=>
'click_game'
,
'game_code'
=>
'ylc'
,
'receive_info'
=>
json_encode
(
$receiveArr
)
);
// add_record($GLOBALS["conn"],'game_global_task',$taddArr);
$taskModel
->
where
(
$whereArr
)
->
add
(
$taddArr
);
}
$result
=
array
(
'c'
=>
1
,
'msg'
=>
'保存成功'
);
}
else
{
$result
=
array
(
'c'
=>
2
,
'msg'
=>
'保存失败'
);
}
return
$result
;
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment