| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 | <?phpdeclare(strict_types=1);namespace App\Services\Interface\Database\Delete;use Illuminate\Support\Facades\DB;use App\Services\Interface\Database\CommonDb;class DeleteDb extends CommonDb{    public function __construct(array $interfaceInfo, array $assembleInfo, array $assembleColumns, array $requestData, array $columnIdToCodes)    {        parent::__construct($interfaceInfo, $assembleInfo, $assembleColumns, $requestData, $columnIdToCodes);    }    public function exec()    {        $delete_type = $this->interfaceSettingInfo['delete_type'] ?? 0;        if (2 === $delete_type) { // 真实删除单条数据            $result = $this->deleteTrueOne();        } elseif (3 === $delete_type) { // 批量伪删除            $result = $this->deleteFakeMulti();        } elseif (1 === $delete_type) { // 伪删除单条数据            $result = $this->deleteFakeOne();        } else {            $result = $this->deleteFakeOne();        }        return $result;    }    /**     * 真实删除.     *     * @return bool     */    public function deleteTrueOne()    {        $entityId = $this->requestData['id'] ?? '';        $entityMid = $this->requestData['mid'] ?? '';        if (empty($entityId) && empty($entityMid)) {            abort(508, '参数错误');        }        $find = DB::connection($this->getDbConnection())->table($this->table);        if ($entityId) {            $find->where('id', $entityId);        }        if ($entityMid) {            $find->where('mid', $entityMid);        }        return $find->delete();    }    /**     * 伪删除.     *     * @return array|callable|false     */    public function deleteFakeOne()    {        $entityId = $this->requestData['id'] ?? '';        $entityMid = $this->requestData['mid'] ?? '';        if (empty($entityId) && empty($entityMid)) {            abort(508, '参数错误');        }        $find = DB::connection($this->getDbConnection())->table($this->table);        if ($entityId) {            $find->where('id', $entityId);        }        if ($entityMid) {            $find->where('mid', $entityMid);        }        $existInfo = $find->first('id');        if (empty($existInfo)) {            abort(508, '参数错误2');        }        return DB::table($this->table)->where('id', $existInfo->id)->update(['is_delete' => 1]);    }    /**     * 批量伪删除.     *     * @return int     */    public function deleteFakeMulti()    {        $idArr = $this->requestData['id'] ?? [];        $midArr = $this->requestData['mid'] ?? [];        if (empty($idArr) && empty($midArr)) {            abort(508, '参数错误');        }//        return DB::table($this->table)->where('id', $id)->orWhere('mid', $mid)->update(['is_delete' => 1]);    }}
 |