12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?php
- namespace Store\Lib;
- use Dever;
- class Goods
- {
-
- public function oper($type, $col, $data)
- {
- if (!$data) {
- return;
- }
- if ($type == 1) {
- $method = 'inc';
- $otherMethod = 'dec';
- } else {
- $method = 'dec';
- $otherMethod = 'inc';
- }
- if ($col == 1) {
- $method .= 'Total';
- $otherMethod .= 'Total';
- $num = 'total_num';
- } else {
- $method .= 'Sell';
- $otherMethod .= 'Sell';
- $num = 'sell_num';
- }
- foreach ($data as $k => $v) {
- if (!$v['sku_id']) {
- $v['sku_id'] = -1;
- }
- $up = array();
- $up['where_store_id'] = $v['store_id'];
- $up['where_goods_id'] = $v['goods_id'];
- $up[$num] = $v['num'];
- $state = Dever::db('store/goods')->$method($up);
- if ($state) {
- $upSku = $up;
- $upSku['where_sku_id'] = $v['sku_id'];
- $state = Dever::db('store/goods_sku')->$method($upSku);
- if (!$state) {
- Dever::db('store/goods')->$otherMethod($up);
- }
- }
- }
- return $state;
- }
- }
|