只要看完题目你就应该明白本次要讲的是什么问题了吧?
) l. f2 X- \* E7 n+ {+ j" D& _ V需要补充的一点就是,这里说的商品库存,
! e; h1 U# j+ d5 ?+ L$ V" m1 B2 l既包括商品总库存(goods表里的goods_number字段),
+ a# e; N9 z' }# z2 a! f也包括货品库存,即不同属性对应的库存(products表里的product_number字段)。1 d+ L1 w( a2 x3 X% }4 |
: c2 p0 M. j' k# _, i
至于为什么会突变为65535,而不是15565,也不是255255,0 V$ ]& D; d' p
那是因为这两个地段的类型都是无符号的 smallint(5),
& |! S/ g; T8 r3 s# V取值范围为 0---65535,所以某个节点某个原因才会突变为 65535。
. k9 q, E7 P' H! y5 z# k
/ M9 o& K! K& Z# i" T下面就具体说一说怎么来防止这种错误的发生。' Y, ]6 A* J% W; m& Y8 M6 m( n
u. @$ C, c9 U: h/ x6 z1)
' P% n* @4 n! s" Z6 h0 m第一步,主要是对 includes/lib_order.php 文件进行一下二次开发。7 {: _2 M7 [ y% \
先找到下面这段代码
& g& |' w6 H. S6 } d: a3 Q% C4 M4 w# y1 ?7 W- V
$number = ($number > 0) ? '+ ' . $number : $number;7 X" C6 u: ]$ m+ x7 U7 ]
: l! |$ z+ w9 a o* h. o
/* 处理货品库存 */
. ^) K! Y0 Q5 @ _8 G3 w3 _' C $products_query = true;
8 d" T. M/ T3 r if (!empty($product_id))0 k* f' C% d' L' X6 i' {) G f
{7 x$ O# G4 f2 ^
$sql = "UPDATE " . $GLOBALS['ecs']->table('products') ."
/ l$ ?8 q" M; P, b4 y: e SET product_number = product_number $number
# ]8 M6 e& z; o- ]! Z3 w' I, M WHERE goods_id = '$good_id'8 a+ T, H! u1 ?& c
AND product_id = '$product_id'
9 k- Z6 P4 S" G, B' j LIMIT 1";; H3 s1 _8 H6 n) Y" ?
$products_query = $GLOBALS['db']->query($sql);* v* `8 h1 @/ S7 R
}8 X5 {# I, R$ g& P
# q1 B7 x, E s$ U& Y /* 处理商品库存 */
: W( G3 f4 |& s% N7 u7 p/ b$ I5 w5 I $sql = "UPDATE " . $GLOBALS['ecs']->table('goods') ."
4 H/ l4 i& L; p) A% R SET goods_number = goods_number $number
# I0 M- _* r2 } WHERE goods_id = '$good_id'$ h. Z" ?9 U& N. v$ y& b
LIMIT 1";
9 X3 k0 J8 M' D- n' v $query = $GLOBALS['db']->query($sql);" O+ W# M. |; n" W5 I" [, V
2 Y- w: h' \+ Q1 @+ [* g$ k7 W 6 K2 c. ?* |& |2 s/ R8 R! s3 H8 Y2 X
% F$ ?. v( R; W4 {( U1 k- _将其修改为
; x) x, q# s9 p& N) k
) a; f+ L( n- m: x# v- ?: M
; S7 q$ i! I* w/ ~) ^if($number>=0)
# h9 _0 c: J; ~: a# B4 z- q& |{
' n+ H X c6 ?$ w1 n /* 处理货品库存 */
1 v8 f2 H4 z- X* R4 m5 d $products_query = true; * l: L9 g5 `/ a0 o: m5 f
if (!empty($product_id))
5 C+ }0 K6 b+ `; D( O, T# A& C {
% G7 J. Q+ z; m0 [* D/ p: s $sql = "UPDATE " . $GLOBALS['ecs']->table('products') .! i& |: A+ q. N3 h; V9 \
" SET product_number = product_number + $number "./ e6 H- M6 U: h" b& n: ^* H% w8 J
" WHERE goods_id = '$good_id' AND product_id = '$product_id' LIMIT 1";
) ^4 D' i' `+ E. K7 Z7 Z $products_query = $GLOBALS['db']->query($sql); & M; n+ V& I( z% s8 \" P9 Q
}
: j) `$ @( X6 P /* 处理商品库存 */
+ w: z! V l& N7 `1 F* F! D $sql = "UPDATE " . $GLOBALS['ecs']->table('goods') .
0 u) Q, u* P' G5 r$ l! a " SET goods_number = goods_number + $number ". ! H) U7 k' \' h! T
" WHERE goods_id = '$good_id' LIMIT 1";
" o w8 K4 m+ B $query = $GLOBALS['db']->query($sql);
# V* A S: d, X} : r Z: h" `* a5 L7 ^
else 0 R e. j' } `5 i4 M# |
{
6 @; ?" K$ c3 z0 L& X /* 处理货品库存 */ 1 W2 x. Z5 s& Y: k
$products_query = true; 4 {+ J* d. p2 B- r3 t, o# \1 }, @
$abs_number = abs($number);
/ w) `) E1 W. p$ s9 ]* N2 P; _2 j if (!empty($product_id))
1 C, x' q: b. V: p {
0 i5 ~8 p4 y F $sql = "UPDATE " . $GLOBALS['ecs']->table('products') . " SET product_number =".; e9 u* X# Z, F. N+ ?6 H4 k
" if( product_number >= $abs_number,product_number - $abs_number,0) ".
: i- m$ c/ O6 |" S4 p) ` " WHERE goods_id = '$good_id' AND product_id = '$product_id' LIMIT 1";
1 J5 i( g9 }: Y* a, Z& R $products_query = $GLOBALS['db']->query($sql); $ L5 L7 t$ x6 N1 r! ]/ n
}
* u8 j8 l6 V3 _) t! O /* 处理商品库存 */ & j% _8 ]9 [. t. p% R' b8 w4 M
$sql = "UPDATE " . $GLOBALS['ecs']->table('goods') . " SET goods_number = ".( D7 A1 `. @ A
" if( goods_number >= $abs_number , goods_number - $abs_number ,0) ". , y# |5 w6 k3 X1 _! q
" WHERE goods_id = '$good_id' LIMIT 1"; * K: t) g+ ^# J4 _! u* g
$query = $GLOBALS['db']->query($sql);
: t* _7 f6 x" U: ?}+ `' P8 V! }2 R3 g+ g* x/ A, g
' F% ~/ Q- Q0 Q
" l: S: u/ f1 j& Q# [2)、
9 p* h. a5 K$ H接下来,还需要修改后台文件 /admin/order.php,
' n; F1 r: T- k8 d$ q) z/ c找到下面代码,大概在811行左右。; z2 ~6 q2 `# L( ~
( O2 C, M/ \% ^ K( O5 T/ j. [& K% @
if (!empty($value['product_id']))
# E, S- A% ^( H% g {. ~; V$ i& }( V z- P- W
$minus_stock_sql = "UPDATE " . $GLOBALS['ecs']->table('products') . "
' R! e; o* C& R, n! Y SET product_number = product_number - " . $value['sums'] . "
8 k, P2 H T$ e; T" j% |8 O) ]0 @2 G3 m WHERE product_id = " . $value['product_id'];) K5 H) \; q9 s/ W2 x$ t2 B
$GLOBALS['db']->query($minus_stock_sql, 'SILENT');
0 a) w5 @5 o! z. V& C/ w% O}
8 D6 [, s/ T6 g
4 I6 U3 o5 k, y; { $minus_stock_sql = "UPDATE " . $GLOBALS['ecs']->table('goods') . " . Z' W4 d/ p/ o6 n0 I. T1 l, H
SET goods_number = goods_number - " . $value['sums'] . "
! W8 V# z5 v: a& j- l: i1 z WHERE goods_id = " . $value['goods_id'];9 L# l# v1 y# p2 N( z5 } Y0 T
9 d: e9 q$ A* B- O. a $GLOBALS['db']->query($minus_stock_sql, 'SILENT');
9 M0 e& W/ f2 |& b
3 ^4 a% o0 y: g4 B4 D& M- J6 V& L3 @ J5 Y0 p1 f! R5 ^
2 A: Z. I- A* c9 Z6 i0 p+ U% n! l
将之修改为3 Y7 S- q/ G) t. e" y, H1 N- O! v5 i5 S
6 v+ Q/ u* o& C& u! L
+ G# j) G' E" r* U. A1 _if (!empty($value['product_id']))
( E" M0 \3 @: I6 q5 G( w* a- C4 {{
0 x4 v4 R4 n, |. m $minus_stock_sql = "UPDATE " . $GLOBALS['ecs']->table('products') . "; U- j' ?- |+ T; g9 |5 i, L
SET product_number = if( product_number > $value[sums], product_number -$value[sums],0 )
" @* ~ G# Q' l& O0 G) U a WHERE product_id = " . $value['product_id'];
b/ e, O" V! @. }3 w7 v: L/ t6 L $GLOBALS['db']->query($minus_stock_sql, 'SILENT');
" r2 o' c( I& A }
& l7 s% u) c' l
* ^8 n& j. e' u7 a4 v; Y $minus_stock_sql = "UPDATE " . $GLOBALS['ecs']->table('goods') . "
9 z6 i7 ]; \1 f+ x SET goods_number = if ( goods_number > $value[sums], goods_number -$value[sums],0 )
; F' [9 }5 Z/ S+ ]% ~; u9 E3 ^ WHERE goods_id = " . $value['goods_id']; f3 X' L% L" W+ Z* r8 ]# F
' m+ P5 O1 Q& y' W) q8 f! K
$GLOBALS['db']->query($minus_stock_sql, 'SILENT');+ b) X2 ~! a* x) q3 }! l. [' R( f
: A8 t! T8 s! r" ?9 @6 l
& M& ?5 Q6 h; [ j, c7 i; i$ z' S" S5 Y5 d. @* I! y1 w9 w
( Q/ R7 {* n& q# [ v) K4 U4 M4 Q/ d |