Files
xo_kf/application/api/model/Order.php
2025-04-26 11:07:05 +08:00

82 lines
2.5 KiB
PHP

<?php
namespace app\api\model;
use think\Db;
use think\Exception;
use think\Log;
use think\Model;
/**
* 订单模型
*/
class Order extends \app\common\model\Order
{
/**
* 查询库存
* @param $type string 卡编码
* @param $number int 数量
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function queryInventory($type, $number)
{
$arr['number'] = 0;
$arr['card_data'] = [];
try {
Db::startTrans();
$junka = new JunkaCard;
$junka_card =
$junka->where(['product_code' => $type])
->where('status', 'in', [1])
->limit(0, $number)
->order('id asc')->select();
$arr['number'] = $junka->where(['product_code' => $type])
->where('status', 'in', [1])
->limit(0, $number)
->order('id asc')->count();
if($junka_card) {
foreach ($junka_card as $kk => $card) {
// // 锁卡的去解锁
// if($card->status == 3) {
// $lock = $this->cardunlock($card);
// // 解锁成功
// if($lock['ret_code'] == 0) {
// $arr['card_data'][] = [
// 'card_number' => $card->card_number,
// 'card_password' => $card->card_password,
// ];
// $card->status = 5; // 状态改成提取中
// }else {
// // 解锁失败 数量 -1
// $arr['number'] -= 1;
// // 失败状态备注
// $card->status_notes = '解锁失败-'. $lock['ret_code'] . '-'. $lock['ret_msg'];
// }
// }else {
$arr['card_data'][] = [
'card_number' => $card->card_number,
'card_password' => $card->card_password,
];;
$card->status = 2; // 状态改成发货
// }
$card->save();
}
}
Db::commit();
return $arr;
}catch (Exception $e) {
Log::write('查询库存错误---' . $e);
Db::rollback();
}
}
}