|
@@ -4,6 +4,7 @@ namespace app\admin\logic;
|
|
|
|
|
|
use app\model\AccountModel;
|
|
|
use app\model\CommonModel;
|
|
|
+use app\model\GoodModel;
|
|
|
use app\model\InventoryExchangeModel;
|
|
|
use think\Exception;
|
|
|
use think\exception\ValidateException;
|
|
@@ -17,19 +18,19 @@ class InventoryExchangeLogic extends BaseLogic
|
|
|
public static function list(array $data = []): Json
|
|
|
{
|
|
|
$db = InventoryExchangeModel::alias('a')
|
|
|
- ->leftJoin('company b', 'b.id=a.company_id')
|
|
|
- ->leftJoin('card c', 'c.id=a.card_id')
|
|
|
- ->where('a.is_del', CommonModel::$del_normal);
|
|
|
+ ->leftJoin('account b', 'b.id=a.account_id AND b.is_del=' . CommonModel::$del_normal);
|
|
|
|
|
|
- if ($data['status'] != '') $db->where('a.status', $data['status']);
|
|
|
- if ($data['company_id'] != '') $db->where('a.company_id', $data['company_id']);
|
|
|
- if ($data['card_id'] != '') $db->where('a.card_id', $data['card_id']);
|
|
|
+ if ($data['status'] != '') $db->where('b.status', $data['status']);
|
|
|
+ if (($data['inventory_start'] != '') && ($data['inventory_end'] != '')) $db->whereBetween('a.inventory', [$data['inventory_start'], $data['inventory_end']]);
|
|
|
+ if ($data['username'] != '') $db->whereLike('a.account_username', '%' . $data['username'] . '%');
|
|
|
+ if ($data['name'] != '') $db->whereLike('a.account_name', '%' . $data['name'] . '%');
|
|
|
+ if ($data['mobile'] != '') $db->whereLike('b.mobile', '%' . $data['mobile'] . '%');
|
|
|
|
|
|
$count = $db->count('a.id');
|
|
|
|
|
|
- $list = $db->field('a.id,b.title company_title,c.title card_title,a.num,a.status,a.addtime,a.is_top')
|
|
|
+ $list = $db->field('a.id,a.account_username,b.status,a.account_name,b.mobile,a.inventory,a.updatetime')
|
|
|
->page($data['page'], $data['size'])
|
|
|
- ->order(['a.is_top' => 'desc', 'a.id' => 'desc'])
|
|
|
+ ->order(['a.id' => 'desc'])
|
|
|
->select()
|
|
|
->toArray();
|
|
|
|
|
@@ -51,41 +52,46 @@ class InventoryExchangeLogic extends BaseLogic
|
|
|
->isEmpty();
|
|
|
if (!$rs) throw new Exception('该账号下的兑换商品库存已存在,不能重复添加');
|
|
|
|
|
|
- $account = AccountModel::field('id,name,nickname')
|
|
|
- ->where(['id'=>$data['account_id']])
|
|
|
+ $account = AccountModel::field('id,username,name')
|
|
|
+ ->where(['id' => $data['account_id'], 'is_del' => CommonModel::$del_normal])
|
|
|
->findOrEmpty();
|
|
|
- if($account->isEmpty()) throw new Exception('该账号不存在');
|
|
|
+ if ($account->isEmpty()) throw new Exception('该账号不存在');
|
|
|
+
|
|
|
+ $good = GoodModel::field('id,good_code,good_name')
|
|
|
+ ->where(['id' => $data['good_id'], 'is_del' => CommonModel::$del_normal])
|
|
|
+ ->findOrEmpty();
|
|
|
+ if ($good->isEmpty()) throw new Exception('该商品不存在');
|
|
|
|
|
|
$date = date('Y-m-d H:i:s');
|
|
|
|
|
|
- $video_group_id = Db::name('video_group')
|
|
|
- ->strict(false)
|
|
|
- ->insertGetId(array_merge($data, [
|
|
|
- 'num' => count($data['video_list']),
|
|
|
- 'is_top' => CommonModel::$top_no,
|
|
|
- 'status' => CommonModel::$status_normal,
|
|
|
- 'is_del' => CommonModel::$del_normal,
|
|
|
- 'createrid' => self::$uid,
|
|
|
- 'creater' => self::$uname,
|
|
|
- 'addtime' => $date,
|
|
|
- 'updaterid' => self::$uid,
|
|
|
- 'updater' => self::$uname,
|
|
|
- 'updatetime' => $date,
|
|
|
- ]));
|
|
|
-
|
|
|
- $da = [];
|
|
|
- foreach ($data['video_list'] as $item) {
|
|
|
- $da[] = [
|
|
|
- 'video_group_id' => $video_group_id,
|
|
|
- 'video_id' => $item['video_id'],
|
|
|
- 'is_top' => $item['is_top'],
|
|
|
- 'is_del' => CommonModel::$del_normal,
|
|
|
- 'addtime' => $date,
|
|
|
- 'updatetime' => $date,
|
|
|
- ];
|
|
|
- }
|
|
|
+ $inventory_exchange_id = Db::name('inventory_exchange')->insertGetId([
|
|
|
+ 'account_id' => $data['account_id'],
|
|
|
+ 'account_username' => $account->username,
|
|
|
+ 'account_name' => $account->name,
|
|
|
+ 'good_id' => $data['good_id'],
|
|
|
+ 'good_code' => $good->good_code,
|
|
|
+ 'good_name' => $good->good_name,
|
|
|
+ 'inventory' => $data['inventory'],
|
|
|
+ 'createrid' => self::$uid,
|
|
|
+ 'creater' => self::$uname,
|
|
|
+ 'addtime' => $date,
|
|
|
+ 'updaterid' => self::$uid,
|
|
|
+ 'updater' => self::$uname,
|
|
|
+ 'updatetime' => $date,
|
|
|
+ ]);
|
|
|
|
|
|
- Db::name('video_group_item')->insertAll($da);
|
|
|
+ Db::name('inventory_exchange_log')->insert([
|
|
|
+ 'inventory_exchange_id' => $inventory_exchange_id,
|
|
|
+ 'before_inventory' => 0,
|
|
|
+ 'after_inventory' => $data['inventory'],
|
|
|
+ 'good_id' => $data['good_id'],
|
|
|
+ 'good_code' => $good->good_code,
|
|
|
+ 'good_name' => $good->good_name,
|
|
|
+ 'source' => CommonModel::$source_admin,
|
|
|
+ 'createrid' => self::$uid,
|
|
|
+ 'creater' => self::$uname,
|
|
|
+ 'addtime' => $date,
|
|
|
+ ]);
|
|
|
|
|
|
Db::commit();
|
|
|
|
|
@@ -102,21 +108,12 @@ class InventoryExchangeLogic extends BaseLogic
|
|
|
public static function read(int $id = 0): Json
|
|
|
{
|
|
|
$res = InventoryExchangeModel::field(true)
|
|
|
- ->where(['id' => $id, 'is_del' => CommonModel::$del_normal])
|
|
|
+ ->where(['id' => $id])
|
|
|
->findOrEmpty()
|
|
|
->toArray();
|
|
|
|
|
|
if (empty($res)) throw new ValidateException('该兑换商品库存为空');
|
|
|
|
|
|
- $res['child'] = Db::name('video_group_item')
|
|
|
- ->alias('a')
|
|
|
- ->field('a.id,a.video_id,a.is_top,a.is_del,b.video_name,b.remark')
|
|
|
- ->leftJoin('video b', 'b.id=a.video_id AND b.is_del=' . CommonModel::$del_normal)
|
|
|
- ->where(['a.is_del' => CommonModel::$del_normal, 'a.video_group_id' => $id])
|
|
|
- ->order(['a.is_top' => 'desc', 'a.id' => 'desc'])
|
|
|
- ->select()
|
|
|
- ->toArray();
|
|
|
-
|
|
|
return json_show(CommonModel::$success, '获取兑换商品库存详情成功', $res);
|
|
|
}
|
|
|
|
|
@@ -126,59 +123,31 @@ class InventoryExchangeLogic extends BaseLogic
|
|
|
Db::startTrans();
|
|
|
try {
|
|
|
|
|
|
- $rs = InventoryExchangeModel::field('id,company_id,card_id')
|
|
|
- ->where([
|
|
|
- 'is_del' => CommonModel::$del_normal,
|
|
|
- 'id' => $data['id']
|
|
|
- ])
|
|
|
+ $rs = InventoryExchangeModel::field('id,inventory,good_id,good_code,good_name')
|
|
|
+ ->lock(true)
|
|
|
+ ->where('id', $data['id'])
|
|
|
->findOrEmpty();
|
|
|
if ($rs->isEmpty()) throw new Exception('该兑换商品库存不存在');
|
|
|
|
|
|
- if (($rs->company_id != $data['company_id']) || ($rs->card_id != $data['card_id'])) {
|
|
|
-
|
|
|
- $temp = InventoryExchangeModel::field('id')
|
|
|
- ->where([
|
|
|
- 'is_del' => CommonModel::$del_normal,
|
|
|
- 'company_id' => $data['company_id'],
|
|
|
- 'card_id' => $data['card_id']
|
|
|
- ])
|
|
|
- ->findOrEmpty()
|
|
|
- ->isEmpty();
|
|
|
- if (!$temp) throw new Exception('该分组已存在');
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
$date = date('Y-m-d H:i:s');
|
|
|
|
|
|
- InventoryExchangeModel::where(['id' => $data['id'], 'is_del' => CommonModel::$del_normal])
|
|
|
- ->strict(false)
|
|
|
- ->save(array_merge($data, ['updatetime' => $date, 'updaterid' => self::$uid, 'updater' => self::$uid]));
|
|
|
-
|
|
|
- $del = $ins = [];
|
|
|
-
|
|
|
- foreach ($data['video_list'] as $item) {
|
|
|
- if (isset($item['id']) && $item['id'] != 0) {
|
|
|
- if ($item['is_del'] == CommonModel::$del_deleted) $del[] = $item['id'];
|
|
|
- else Db::name('video_group_item')->where('is_del', CommonModel::$del_normal)->where('id', $item['id'])->save(array_merge($item, ['updatetime' => $date]));
|
|
|
- } else $ins[] = [
|
|
|
- 'video_group_id' => $data['id'],
|
|
|
- 'video_id' => $item['video_id'],
|
|
|
- 'is_top' => $item['is_top'],
|
|
|
- 'is_del' => CommonModel::$del_normal,
|
|
|
+ if ($rs->inventory != $data['inventory']) {
|
|
|
+ Db::name('inventory_exchange_log')->insert([
|
|
|
+ 'inventory_exchange_id' => $data['id'],
|
|
|
+ 'before_inventory' => $rs->inventory,
|
|
|
+ 'after_inventory' => $data['inventory'],
|
|
|
+ 'good_id' => $rs->good_id,
|
|
|
+ 'good_code' => $rs->good_code,
|
|
|
+ 'good_name' => $rs->good_name,
|
|
|
+ 'source' => CommonModel::$source_admin,
|
|
|
+ 'createrid' => self::$uid,
|
|
|
+ 'creater' => self::$uname,
|
|
|
'addtime' => $date,
|
|
|
- 'updatetime' => $date,
|
|
|
- ];
|
|
|
- }
|
|
|
-
|
|
|
- if ($del) Db::name('video_group_item')
|
|
|
- ->whereIn('id', $del)
|
|
|
- ->where('is_del', CommonModel::$del_normal)
|
|
|
- ->update([
|
|
|
- 'is_del' => CommonModel::$del_deleted,
|
|
|
- 'updatetime' => $date,
|
|
|
]);
|
|
|
+ }
|
|
|
|
|
|
- if ($ins) Db::name('video_group_item')->insertAll($ins);
|
|
|
+ InventoryExchangeModel::where('id', $data['id'])
|
|
|
+ ->save(array_merge($data, ['updatetime' => $date, 'updaterid' => self::$uid, 'updater' => self::$uid]));
|
|
|
|
|
|
Db::commit();
|
|
|
|
|
@@ -191,46 +160,24 @@ class InventoryExchangeLogic extends BaseLogic
|
|
|
|
|
|
}
|
|
|
|
|
|
- //兑换商品库存启禁用
|
|
|
- public static function status(array $data = []): Json
|
|
|
+ //兑换商品库存变动记录
|
|
|
+ public static function log(array $data = []): Json
|
|
|
{
|
|
|
- $res = InventoryExchangeModel::where('id', $data['id'])
|
|
|
- ->where('status', '<>', $data['status'])
|
|
|
- ->save([
|
|
|
- 'status' => $data['status'],
|
|
|
- 'updatetime' => date('Y-m-d H:i:s'),
|
|
|
- ]);
|
|
|
-
|
|
|
- return $res ? json_show(CommonModel::$success, '操作成功') : json_show(CommonModel::$success, '操作失败');
|
|
|
-
|
|
|
- }
|
|
|
+ $count = Db::name('inventory_exchange_log')
|
|
|
+ ->where('inventory_exchange_id', $data['id'])
|
|
|
+ ->count('id');
|
|
|
|
|
|
- //删除兑换商品库存
|
|
|
- public static function delete(int $id = 0): Json
|
|
|
- {
|
|
|
- $res = InventoryExchangeModel::where('id', $id)
|
|
|
- ->where('is_del', CommonModel::$del_normal)
|
|
|
- ->save([
|
|
|
- 'is_del' => CommonModel::$del_deleted,
|
|
|
- 'updatetime' => date('Y-m-d H:i:s'),
|
|
|
- ]);
|
|
|
+ $res = Db::name('inventory_exchange_log')
|
|
|
+ ->field('id,before_inventory,after_inventory,good_id,good_code,good_name,source,creater,addtime')
|
|
|
+ ->where('inventory_exchange_id', $data['id'])
|
|
|
+ ->page($data['page'], $data['size'])
|
|
|
+ ->order('id', 'desc')
|
|
|
+ ->select()
|
|
|
+ ->toArray();
|
|
|
|
|
|
- return $res ? json_show(CommonModel::$success, '删除成功') : json_show(CommonModel::$error_param, '删除失败');
|
|
|
+ return $res ? json_show(CommonModel::$success, '获取兑换商品库存变动记录成功', ['count' => $count, 'list' => $res]) : json_show(CommonModel::$success, '获取兑换商品库存变动记录失败');
|
|
|
|
|
|
}
|
|
|
|
|
|
- //兑换商品库存置顶
|
|
|
- public static function top(array $data = []): Json
|
|
|
- {
|
|
|
- $res = InventoryExchangeModel::where('id', $data['id'])
|
|
|
- ->where('is_top', '<>', $data['is_top'])
|
|
|
- ->save([
|
|
|
- 'is_top' => $data['is_top'],
|
|
|
- 'updatetime' => date('Y-m-d H:i:s'),
|
|
|
- ]);
|
|
|
-
|
|
|
- return $res ? json_show(CommonModel::$success, '操作成功') : json_show(CommonModel::$success, '操作失败');
|
|
|
-
|
|
|
- }
|
|
|
|
|
|
}
|