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
18a26e69
Commit
18a26e69
authored
Sep 29, 2018
by
734642908@qq.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加购买虚拟商品
parent
11492537
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
123 additions
and
74 deletions
+123
-74
ShopController.class.php
Application/Home/Controller/ShopController.class.php
+1
-1
ShopModel.class.php
Application/Home/Model/ShopModel.class.php
+122
-73
No files found.
Application/Home/Controller/ShopController.class.php
View file @
18a26e69
...
...
@@ -101,7 +101,7 @@ class ShopController extends BaseController
if
(
$isShow
==
1
)
{
$whereArr
[
'is_show'
]
=
$isShow
;
}
$field
=
'sysid as order_id,goods_id,name,icon,gold,status,create_time'
;
$field
=
'sysid as order_id,goods_id,name,icon,gold,status,create_time
,goods_type,redeem_code
'
;
$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
(
...
...
Application/Home/Model/ShopModel.class.php
View file @
18a26e69
...
...
@@ -15,101 +15,150 @@ class ShopModel extends BaseModel
);
}
//查询收获信息
$addressArr
=
M
(
"game_member_address"
,
""
,
$this
->
__lewan_hezi
)
->
where
(
array
(
'uid'
=>
$uid
,
'game_code'
=>
'ylc'
))
->
find
();
if
(
empty
(
$addressArr
))
{
return
$result
=
array
(
'c'
=>
2
,
'msg'
=>
'请先填写收获信息'
);
//判断商品类型:虚拟 OR 实物
if
(
$goodsArr
[
'type'
]
==
2
)
{
//获取虚拟商品兑换码
$codeArr
=
M
(
"yl_goods_redeemcode"
,
""
,
$this
->
__lewan_hezi
)
->
where
(
array
(
'goods_id'
=>
$goodsId
,
'status'
=>
1
,
'game_code'
=>
'ylc'
))
->
order
(
'create_time'
)
->
field
(
'sysid,redeem_code'
)
->
find
();
if
(
empty
(
$codeArr
))
{
return
$result
=
array
(
'c'
=>
2
,
'msg'
=>
'兑换失败,库存不足'
);
}
}
else
{
//查询收获信息
$addressArr
=
M
(
"game_member_address"
,
""
,
$this
->
__lewan_hezi
)
->
where
(
array
(
'uid'
=>
$uid
,
'game_code'
=>
'ylc'
))
->
find
();
if
(
empty
(
$addressArr
))
{
return
$result
=
array
(
'c'
=>
2
,
'msg'
=>
'请先填写收获信息'
);
}
}
//判断兑换方式
if
(
$changeWay
==
1
)
{
//直接金币兑换
try
{
$memberModel
=
M
(
"game_member"
,
""
,
$this
->
__lewan_hezi
);
$memberModel
->
startTrans
();
try
{
//扣除商品库存
$reStock
=
M
(
"yl_goods"
,
""
,
$this
->
__lewan_hezi
)
->
where
(
array
(
'sysid'
=>
$goodsId
))
->
setDec
(
'stock'
,
1
);
//商品订单通用数据
$orderArr
=
array
(
'uid'
=>
$uid
,
'goods_id'
=>
$goodsId
,
'name'
=>
$goodsArr
[
'name'
]
,
'icon'
=>
$goodsArr
[
'icon'
]
,
'goods_type'
=>
$goodsArr
[
'type'
]
,
'create_time'
=>
date
(
'Y-m-d H:i:s'
)
,
'game_code'
=>
'ylc'
);
//判断兑换方式
if
(
$changeWay
==
1
)
{
//直接金币兑换
//扣除用户金币
$re
1
=
$memberModel
->
where
(
array
(
'uid'
=>
$uid
))
->
setDec
(
'gold'
,
$goodsArr
[
'initial_price'
]);
$re
MemberGold
=
$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'
=>
'兑换失败,玩币不足'
);
$orderArr
[
'change_way'
]
=
1
;
$orderArr
[
'gold'
]
=
$goodsArr
[
'initial_price'
];
$orderArr
[
'status'
]
=
2
;
$orderArr
[
'pay_time'
]
=
date
(
'Y-m-d H:i:s'
);
if
(
$goodsArr
[
'type'
]
==
2
)
{
//更新商品兑换码状态
$re1
=
M
(
"yl_goods_redeemcode"
,
""
,
$this
->
__lewan_hezi
)
->
where
(
array
(
'sysid'
=>
$codeArr
[
'sysid'
]))
->
save
(
array
(
'status'
=>
2
,
'uid'
=>
$uid
,
'redeem_time'
=>
date
(
'Y-m-d H:i:s'
)));
$orderArr
[
'redeem_code'
]
=
$codeArr
[
'redeem_code'
];
}
else
{
$re1
=
1
;
$orderArr
[
'consignee'
]
=
$addressArr
[
'consignee'
];
$orderArr
[
'phone'
]
=
$addressArr
[
'phone'
];
$orderArr
[
'address'
]
=
$addressArr
[
'address'
];
}
//生成订单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
;
}
}
if
(
!
$re2
)
{
return
$result
=
array
(
//记录商品订单
$orderArr
[
'sysid'
]
=
$orderId
;
// $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']
// ,'consignee'=>$addressArr['consignee']
// ,'phone'=>$addressArr['phone']
// ,'address'=>$addressArr['address']
// ,'redeem_code'=>$redeem_code
// );
$re2
=
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'
);
$re3
=
M
(
"game_member_gold"
,
""
,
$this
->
__lewan_hezi
)
->
add
(
$goldArr
);
if
(
$re1
&&
$re2
&&
$re3
)
{
$memberModel
->
commit
();
$result
=
array
(
'c'
=>
1
,
'msg'
=>
'兑换成功'
,
'd'
=>
array
(
'stock'
=>
$goodsArr
[
'stock'
]
-
1
)
);
}
else
{
$result
=
array
(
'c'
=>
2
,
'msg'
=>
'兑换失败
,库存不足
'
,
'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'
]
,
'consignee'
=>
$addressArr
[
'consignee'
]
,
'phone'
=>
$addressArr
[
'phone'
]
,
'address'
=>
$addressArr
[
'address'
]
);
$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'
=>
'兑换成功'
,
'd'
=>
array
(
'stock'
=>
$goodsArr
[
'stock'
]
-
1
)
}
catch
(
\Exception
$e
)
{
if
(
!
$reStock
)
{
return
$result
=
array
(
'c'
=>
2
,
'msg'
=>
'兑换失败,库存不足'
);
}
else
{
$result
=
array
(
}
if
(
!
$reMemberGold
)
{
return
$result
=
array
(
'c'
=>
2
,
'msg'
=>
'兑换失败'
,
'msg'
=>
'兑换失败
,玩币不足
'
);
}
}
return
$result
;
}
...
...
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