|
|
@@ -226,44 +226,67 @@ class WorkOrder extends Api
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * U8工单资料删除(软删除)
|
|
|
- * @param string Uniqid 工单Uniqid
|
|
|
+ * U8工单资料批量删除(软删除)
|
|
|
+ * @param string Uniqid 工单Uniqid,多个用英文逗号拼接
|
|
|
*/
|
|
|
public function orderDataDel()
|
|
|
{
|
|
|
if (!$this->request->isGet()) {
|
|
|
$this->error('请求错误');
|
|
|
}
|
|
|
- $uniqid = $this->request->param('Uniqid');
|
|
|
- if (empty($uniqid)) {
|
|
|
+ $uniqidParam = $this->request->param('Uniqid');
|
|
|
+ if (empty($uniqidParam)) {
|
|
|
$this->error('参数错误');
|
|
|
}
|
|
|
|
|
|
- $order = Db::table('工单_基本资料')
|
|
|
- ->where('Uniqid|UniqId', $uniqid)
|
|
|
+ $uniqids = array_values(array_unique(array_filter(array_map('trim', explode(',', $uniqidParam)))));
|
|
|
+ if (empty($uniqids)) {
|
|
|
+ $this->error('参数错误');
|
|
|
+ }
|
|
|
+
|
|
|
+ $orders = Db::table('工单_基本资料')
|
|
|
+ ->where(function ($query) use ($uniqids) {
|
|
|
+ $query->whereIn('Uniqid', $uniqids)->whereOr('UniqId', 'in', $uniqids);
|
|
|
+ })
|
|
|
->whereNull('Mod_rq')
|
|
|
->field('Uniqid,UniqId,订单编号')
|
|
|
- ->find();
|
|
|
- if (empty($order)) {
|
|
|
+ ->select();
|
|
|
+ if (empty($orders)) {
|
|
|
$this->error('工单不存在或已删除');
|
|
|
}
|
|
|
|
|
|
- $orderNo = $order['订单编号'];
|
|
|
+ $foundKeys = [];
|
|
|
+ foreach ($orders as $order) {
|
|
|
+ if (!empty($order['Uniqid'])) {
|
|
|
+ $foundKeys[$order['Uniqid']] = true;
|
|
|
+ }
|
|
|
+ if (!empty($order['UniqId'])) {
|
|
|
+ $foundKeys[$order['UniqId']] = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $notFound = array_diff($uniqids, array_keys($foundKeys));
|
|
|
+ if (!empty($notFound)) {
|
|
|
+ $this->error('部分工单不存在或已删除:' . implode(',', $notFound));
|
|
|
+ }
|
|
|
+
|
|
|
+ $orderNos = array_unique(array_column($orders, '订单编号'));
|
|
|
$now = date('Y-m-d H:i:s');
|
|
|
$softDelete = ['Mod_rq' => $now];
|
|
|
|
|
|
Db::startTrans();
|
|
|
try {
|
|
|
Db::table('工单_印件资料')
|
|
|
- ->where('订单编号', $orderNo)
|
|
|
+ ->whereIn('订单编号', $orderNos)
|
|
|
->whereNull('Mod_rq')
|
|
|
->update($softDelete);
|
|
|
Db::table('工单_工艺资料')
|
|
|
- ->where('订单编号', $orderNo)
|
|
|
+ ->whereIn('订单编号', $orderNos)
|
|
|
->whereNull('Mod_rq')
|
|
|
->update($softDelete);
|
|
|
$result = Db::table('工单_基本资料')
|
|
|
- ->where('Uniqid|UniqId', $uniqid)
|
|
|
+ ->where(function ($query) use ($uniqids) {
|
|
|
+ $query->whereIn('Uniqid', $uniqids)->whereOr('UniqId', 'in', $uniqids);
|
|
|
+ })
|
|
|
->whereNull('Mod_rq')
|
|
|
->update($softDelete);
|
|
|
if ($result === false) {
|
|
|
@@ -280,7 +303,7 @@ class WorkOrder extends Api
|
|
|
$this->error('删除失败:' . $e->getMessage());
|
|
|
}
|
|
|
|
|
|
- $this->success('成功');
|
|
|
+ $this->success('成功', ['count' => count($orders)]);
|
|
|
}
|
|
|
|
|
|
|